You can inherit from a single parent downwards as far as you want...
A extends Object; B extends A; C extends B; etc
Thus, by implication, C extends B, A, and Object.
What you can't do is this:
E extends F,G
ie. extend from two parents at the same level. This is what Java refers to a multiple inheritance.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Yeah interfaces are somewhat similar - if your class "implements" the interface, it forces you to include those methods that are defined in the interface itself.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
In effect, if your class does not explicity specify an "extends" superclass, then the superclass is taken to be Object. It's that simple.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
It's single inheritance. Each class inherits from 1 class only, but that class, in turn,inherits from one class, etc, all the way up to Object.
When your code refers to a method or variable in a class Java looks for that method/variable in the class definition. If it finds it, OK. If not, it looks in the definition of the superclass. If it finds it there, OK. If not, it looks in that classes' superclass etc, all the way to Object. I it doesn't find it in Object you get a compile error.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
That's part pf the language definition. If you don't specify an "extends" then your class extends Object. It's built into the compiler.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
I'm not sure what distinction you are trying to make here. A class can only extend one class. That class, in turn, can only extend one class, etc all the way to Object.
Consider
class A {...}
which is exactly the same as
class A extends Object {...}
then
class B extends A {...}
class C extends B {...}
...
class Z extends Y {...}
It would be totally misleading to say "class Z extends Y and Object" without mentioning B..Y
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073