This discussion is archived
7 Replies Latest reply: May 2, 2009 9:36 AM by 3004 RSS

Doesn't Java Support Indirect Multiple Inheritance ?

843789 Newbie
Currently Being Moderated
Every Java Class extends the Object Class.Also it is free to extend any other Class.So even though not visibly but we are actually extending two classes and also sometimes we use the functionality of Object Class (using its methods..)

Hence is it only because it is defined ,does Java not support Multiple Inheritance ?
What is the Java thesis against this fact that says Java not support Multiple Inheritance

Thank you for your consideration.

Edited by: amtidumpti on May 1, 2009 10:57 AM
  • 1. Re: Doesn't Java Support Indirect Multiple Inheritance ?
    EJP Guru
    Currently Being Moderated
    Every Java Class extends the Object Class.
    Directly or indirectly.
    Also it is free to extend any other Class.
    Not also. Instead of.
    So even though not visibly but we are actually extending two classes
    No.
  • 2. Re: Doesn't Java Support Indirect Multiple Inheritance ?
    843789 Newbie
    Currently Being Moderated
    class MySuperClass
    {
      public String returnGreetings()
      {
           return "GOOD DAY MATE";
      }
    }
    public class MySubClass extends MySuperClass {
    
         
         public static void main(String[] args) {
         
               MySubClass objMySubClass=new  MySubClass();
              System.out.println(objMySubClass.returnGreetings());
                    System.out.println(objMySubClass.getClass());
    
    }
    }
    Here since I am getting Object class behavior ,aren't I actually indirectly extending two classes ? If not how did I get the Object Class methods ?

    My question may seem to be stupid but i have to be honest on the forums !!!!
  • 3. Re: Doesn't Java Support Indirect Multiple Inheritance ?
    EJP Guru
    Currently Being Moderated
    class MySuperClass
    [extends Object]
    public class MySubClass extends MySuperClass {
    Here since I am getting Object class behavior ,aren't I actually indirectly extending two classes?
    No, MySubClass extends MySuperClass and MySuperClass extends Object.
    If not how did I get the Object Class methods?
    Because it's the super-superclass of MySubClass. Inheritance can go as deep as you like.
  • 4. Re: Doesn't Java Support Indirect Multiple Inheritance ?
    843789 Newbie
    Currently Being Moderated
    Got it...
    "Dhanyavad Mitra..." ("Thank you,friend "in my mother tongue !!!)
  • 5. Re: Doesn't Java Support Indirect Multiple Inheritance ?
    3004 Newbie
    Currently Being Moderated
    amtidumpti wrote:
    does Java not support Multiple Inheritance ?
    It depends on your definition of MI. If your definition is this:
    A
    |
    B
    |
    C
    then yes, Java supports MI. But if your definition is in line with everybody else's:
       A
      /  \
     B    C
    then no, Java does not support MI of implementation. It does, however support MI of interface, of type, which is really what inheritance is about anyway.
  • 6. Re: Doesn't Java Support Indirect Multiple Inheritance ?
    843789 Newbie
    Currently Being Moderated
    jverd wrote:
    amtidumpti wrote:
    does Java not support Multiple Inheritance ?
    It depends on your definition of MI. If your definition is this:
    A
    |
    B
    |
    C
    then yes, Java supports MI. But if your definition is in line with everybody else's:
    A
    /  \
    B    C
    then no, Java does not support MI of implementation. It does, however support MI of interface, of type, which is really what inheritance is about anyway.
    But that's still not multiple inheritance.
    I think what you meant is.
    B C
    \ /
    A
    ------------------------------
    tommickey

    Edited by: tommickey on May 2, 2009 3:16 AM

    Edited by: tommickey on May 2, 2009 3:17 AM
  • 7. Re: Doesn't Java Support Indirect Multiple Inheritance ?
    3004 Newbie
    Currently Being Moderated
    tommickey wrote:
    jverd wrote:
    amtidumpti wrote:
    does Java not support Multiple Inheritance ?
    It depends on your definition of MI. If your definition is this:
    A
    |
    B
    |
    C
    then yes, Java supports MI. But if your definition is in line with everybody else's:
    A
    /  \
    B    C
    then no, Java does not support MI of implementation. It does, however support MI of interface, of type, which is really what inheritance is about anyway.
    But that's still not multiple inheritance.
    I think what you meant is.
    B C
    \ /
    A
    ------------------------------
    tommickey

    Edited by: tommickey on May 2, 2009 3:16 AM

    Edited by: tommickey on May 2, 2009 3:17 AM
    Oops, you're right. I had it backwards. Careless.

    The usual definition of MI is
      B   C
       \ /
        A
    And Java supports MI of type that way, but not MI of implementation.