Reputation: 41
Since I am new to java. I want to know if multiple ineritance is not supported in java then how a class extends another class alongwith the default superclass Object?
Upvotes: 4
Views: 4457
Reputation: 1893
Although this is already answered, here is a diferent perspective. Try to think of it in human terms. You can't have 2 biological fathers, but you inherit the traits from your father, your grandfather, great grandfather and so on... In the same way, when you extend a class, that class becomes the parent class and you'll inherit traits from every parent class up the tree.
;)
Upvotes: 3
Reputation: 1550
There are two similar sounding concepts related to inheritance Multiple Inheritance and Multi-Level Inheritance.
Multiple Inheritance is not allowed in java. This stops a class from inheriting multiple classes. For example we can't declare a class as:
Class C extends A, C
But as multilevel inheritance is allowed, extending of class B, which extends class A, by class C is allowed. So class hierarchies like
Class B extends A
and
Class C extends B
is allowed.
Upvotes: 2
Reputation: 139931
"Multiple inheritance" is different than what you describe - it refers to a single class extending more than one class, such as
public class MultipleClass extends ClassA, ClassB
What you have described is just a hierarchy of inheritance.
Upvotes: 0
Reputation: 72294
Because although multiple inheritance isn't allowed, one class can inherit from another which can inherit from another - and eventually the class at the top of that chain will inherit from object (it'll do that if you don't specify any specific class for it to inherit from.)
Upvotes: 6