2 Replies Latest reply: Feb 8, 2014 12:56 PM by 51dfae5b-b298-49e8-af8f-58ab1c731cc7 RSS

    Difference between Multiple Inheritance and Generaliztion

    51dfae5b-b298-49e8-af8f-58ab1c731cc7

      As what i understand, Generalization is also know as  Inheritance and Aggregation. They may or may not co-exist in order for a class to work. The subclass and the super class

       

      and on the other hand, multiple inheritance is not allowed in Java, Can anyone please explain to me how these two differs.

       

      Thanks in advance

        • 1. Re: Difference between Multiple Inheritance and Generaliztion
          TPD-Opitz

          51dfae5b-b298-49e8-af8f-58ab1c731cc7 wrote:

           

          As what i understand, Generalization is also know as  Inheritance and Aggregation.

          No.

          Generalization and Inheritance are almost the same thing viewed from opposite direction. A class inherits behavior and properties from its supper class while a supper class is a generalization to its subclasses which means it provides equal behavior common for all the subclasses. -> Human is a subclass of Mammal and Mammal is a super class of Human and Dog.

           

          Aggregation has nothing to do with either one. It means that an object of on class contains and uses objects of other classes. -> A Car is an aggregation of Engine, Chassis, Transmission, Wheel,...

          51dfae5b-b298-49e8-af8f-58ab1c731cc7 wrote:

          They may or may not co-exist in order for a class to work.

          Inherittance/Generalisation and Aggregation are concepts. They cannot "exist" in your program. You can use it or not.

           

          51dfae5b-b298-49e8-af8f-58ab1c731cc7 wrote:

          The subclass and the super class and on the other hand, multiple inheritance is not allowed in Java, [...]

          Multiple inheritance leads to problems: Imagine you have this structure:

           

          class A {
              void someMethod(){
                 System.println("in A");
          }
          }
          class B extends A {
              void someMethod(){
                 System.println("in B");
          }
          }
          
          class C extends A {
              void someMethod(){
                 System.println("in C");
          }
          }
          
          class D extends B,C {
          }
          
          

          what result do you expect when calling

          new D().someMethod();
          
          

          ?

           

          Java solves this by not having multiple inheritance. Despite of this Java allows to implement multiple interfaces. In contrary to multiple inheritance there is no problem when different interfaces declare the same method signature.

           

          bye

          TPD