1

If every class in Java implicitly extends Object class and multiple inheritance is not possible in Java then how do we even extend any class?

4
  • Because single inheritancy is chained from one class to the next. Multiple inheritancy deals with extending from two or more objects within a single generation Commented Apr 11, 2013 at 6:01
  • 1
    Read about difference between multiple and multi level inheritance. Commented Apr 11, 2013 at 6:03
  • stackoverflow.com/questions/13926555/… and stackoverflow.com/questions/7553201/… Commented Apr 11, 2013 at 6:12
  • @Habib I don't have any confusion regarding Multiple or Multi-level inheritance. Anyways got my doubt cleared.Thanx Commented Apr 11, 2013 at 6:24

5 Answers 5

3

If you extend a class A that class in turn extends Object, so B extends A implicitly also extends Object.

Sign up to request clarification or add additional context in comments.

Comments

3

"Java doesn't have multiple inheritance" means that you can't have two different parents, not that your parent can't have a parent.

C++ is an example of a language that lets you do multiple inheritance: http://www.learncpp.com/cpp-tutorial/117-multiple-inheritance/

Multiple inheritance looks like this:

class Teacher: public Person, public Employee

which means 'Teacher extends Person and Employee, inheriting its fields and methods'.

Instead of multiple inheritance, you're expected to create and implement interfaces to represent all the behaviours (or contracts if you prefer) your object supports. Java uses this for interfaces like Closeable and Serializable.

3 Comments

@MadProgrammer Hopefully my edit makes it clearer what I mean.
Exactly my point. You cannot have two different parents but when you extend a class you get two parents, Object and the one that you extended
@Patashu Thank you :D - It's late and my brains a little wishy washy :P
1

Multiple Inheritance is the concept of a single class inheriting from two or more super classes. If a class inherits from a super class and if that super class inherits from another super class it does NOT qualify as Multiple Inheritance. It is still Single Inheritance.

once u create object of sub class the object hierachy would be create on order of

objectclaass–>superclass—>subclass;

It is true that every class in Java inherits from the Object class – either indirectly or directly.

so in this case the sub class indirectly inherits object class.

Comments

1

Every Class that dosn't extends any other class it extends Object class. if you extends anther class example extends Vector class look to the hierarchy of class Vector you will end with a simple class that dosn't extends any anther class which explicitly extends Object. and Any class extends anther class it explicitly extends all class that the parent class extends.

Comments

0

There is no multiple inheritance in Java, but there is class hierarchy. Inheritance in Java is transitive: if class A extends Object and class B extends A, than by transitivity A extends Object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.