MULTIPLE INHERITANCE IN JAVA?

Discussion in 'Java' started by nirmal, Jun 19, 2005.

  1. nirmal

    nirmal Guest

    hi everyone
    this is my first post since i joined the group a week ago.
    I m working with java for a year now since i come from a C++
    background i can't help comparing the two languages.
    While studying for java i found many books stating that java does not
    support multiple inheritance i don't fully agree with this notion
    (please don't hate me for that).
    Though it is true that one cannot extend more than one class at a time
    which makes perfect sense
    since all the classes in java are derived from Object class and
    multiple extensions would
    cause multiple objects of Object to exist in the code which could be
    undesirable.However java could
    have provided a concept similar to virtual base classes in C++ but it
    would have to be implicit like the extension to
    the Object class and moreover multiple calls to the virtual base
    class's(Object) constructor would have to be avoided.
    (in C++ the compiler donot call the constructor of a virtual base class
    from immediate derivations
    rather it allows the class which is extending multiple derivations of
    the virtual base class to call its
    constructor directly, something which is not legal for ordinary base
    classes) .Java could not provide a solution like this
    since the only way to call the superclass constructor is by keyword
    super which can call the constructor of
    the immediate superclass only.So it is true that allowing multiple
    extensions would have caused more problems
    than it could solve.Still while creating patterns multiple inheritance
    is sometimes inevitable.The solution to this
    problem is interface.An interface in java is used to create a model of
    a class,it just declare the behaviour(methods) that
    a class must implement.It is worth noting that code reusabilty ,a
    criteria generally used to define inheritance,while implementing an
    interface is nil.That is why implementing an interface is not qualified
    as inheritance.However if you have ever indulged yourself in creating
    design patterns you would know that inheritance is more than just code
    reusability rather in my opinion code reusability is just a consequence
    of implementing inheritance in programming languages. Java allows a
    class to implement more than one interface in this way a class can
    implement 'behaviours' of multiple classes and thus to an extent
    solving the multiple inheritance problem(without providing code
    reusability).
    So the question is that is it alright to say that java does not
    support multiple inheritance?

    nirmal.
    nirmal, Jun 19, 2005
    #1
    1. Advertising

  2. Andrew Thompson, Jun 19, 2005
    #2
    1. Advertising

  3. nirmal

    nirmal Guest

    since this was my first post i was a little keen to get attention
    also i put the same message twice
    my apologies
    nirmal, Jun 19, 2005
    #3
  4. "nirmal" <> writes:

    > So the question is that is it alright to say that java does not
    > support multiple inheritance?


    Java does not support multiple *implementation* inheritance.

    It does support multiple interface inheritance.

    Since the former is usually what people mean when they say "multiple
    inheritance", the simple answer is that Java doens't support it.

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Jun 19, 2005
    #4
  5. nirmal

    Hal Rosser Guest

    > So the question is that is it alright to say that java does not
    > support multiple inheritance?
    >


    Yes.
    Hal Rosser, Jun 20, 2005
    #5
  6. nirmal

    Wibble Guest

    nirmal wrote:
    > hi everyone
    > this is my first post since i joined the group a week ago.
    > I m working with java for a year now since i come from a C++
    > background i can't help comparing the two languages.
    > While studying for java i found many books stating that java does not
    > support multiple inheritance i don't fully agree with this notion
    > (please don't hate me for that).
    > Though it is true that one cannot extend more than one class at a time
    > which makes perfect sense
    > since all the classes in java are derived from Object class and
    > multiple extensions would
    > cause multiple objects of Object to exist in the code which could be
    > undesirable.However java could
    > have provided a concept similar to virtual base classes in C++ but it
    > would have to be implicit like the extension to
    > the Object class and moreover multiple calls to the virtual base
    > class's(Object) constructor would have to be avoided.
    > (in C++ the compiler donot call the constructor of a virtual base class
    > from immediate derivations
    > rather it allows the class which is extending multiple derivations of
    > the virtual base class to call its
    > constructor directly, something which is not legal for ordinary base
    > classes) .Java could not provide a solution like this
    > since the only way to call the superclass constructor is by keyword
    > super which can call the constructor of
    > the immediate superclass only.So it is true that allowing multiple
    > extensions would have caused more problems
    > than it could solve.Still while creating patterns multiple inheritance
    > is sometimes inevitable.The solution to this
    > problem is interface.An interface in java is used to create a model of
    > a class,it just declare the behaviour(methods) that
    > a class must implement.It is worth noting that code reusabilty ,a
    > criteria generally used to define inheritance,while implementing an
    > interface is nil.That is why implementing an interface is not qualified
    > as inheritance.However if you have ever indulged yourself in creating
    > design patterns you would know that inheritance is more than just code
    > reusability rather in my opinion code reusability is just a consequence
    > of implementing inheritance in programming languages. Java allows a
    > class to implement more than one interface in this way a class can
    > implement 'behaviours' of multiple classes and thus to an extent
    > solving the multiple inheritance problem(without providing code
    > reusability).
    > So the question is that is it alright to say that java does not
    > support multiple inheritance?
    >
    > nirmal.
    >

    You should start another thread with this too. You can never announce
    your ignorance too loudly!
    Wibble, Jun 20, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hung Jung Lu
    Replies:
    5
    Views:
    861
  2. maxw_cc
    Replies:
    1
    Views:
    3,112
    Martijn van Steenbergen
    Dec 21, 2003
  3. nirmal

    Multiple Inheritance In Java

    nirmal, Jun 19, 2005, in forum: Java
    Replies:
    7
    Views:
    904
    Hal Rosser
    Jun 20, 2005
  4. Murat Tasan
    Replies:
    1
    Views:
    7,785
    Murat Tasan
    Jun 22, 2005
  5. Rouslan Korneychuk
    Replies:
    8
    Views:
    569
    Rouslan Korneychuk
    Feb 10, 2011
Loading...

Share This Page