AllExperts > Experts 
Search      

Java

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Java Answers
Question Library

Ask a question about Java
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Neal Ziring
Expertise
Almost anything about the core Java platform, with an emphasis on networking. Not familiar with JDBC or the new Java graphics APIs. [Sun Certified Java Programmer, JDK 1.1]

Experience
Certified Java Programmer for JDK 1.1 and 2.0.
 
   

You are here:  Experts > Computing/Technology > Focus on Java > Java > Multiple Inheritance in Java

Topic: Java



Expert: Neal Ziring
Date: 5/28/2008
Subject: Multiple Inheritance in Java

Question
All java classes, by default, extend Object class.
public class ABC is equivalent to public class ABC extends Object
So all java classes are the sub classes of the class Object.
But even though, we can extend other class:-
public class ABC extends XYZ - so its a multiple inheritance which is
not supported by JAVA.
Can you explain this behavior?  

Answer
Preeyanka,

Java does not have multiple inheritance for classes.

Consider these two declarations:


           class ABC extends Object {
                . . .
           }

           class DEF extends ABC {
                . . .
           }

DEF extends ABC, but ABC already extends Object.  Thus, DEF
extends Object indirectly.  

In Java, each class has exactly one direct super-class.  It may
have several indirect superclasses, but that is not a form of
multiple inheritance.


Java does have multiple inheritance for interfaces.  An interface
can extend several other interfaces, and a class can implement
multiple interfaces.

For more information, see these articles:

http://pclc.pace.edu/~bergin/patterns/multipleinheritance.html
http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html
http://www.csupomona.edu/~dlbell/cppexplanationsfa99/151.html


Hope this helps...

...nz


Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.