I have a simple question:
If I declare a class A - means this class in implicitly inheriting from Object Class.
Now If class B inherits from class A
is this Class B also not Inheriting from Object class ?
If yes, does that mean writing the keyword 'extends' some how override the implicit inheritance ( from class Object) ?
All classes extend form Object, either implicitly or explicitly, directly or indirectly, the whole class hierarchy in Java ends up pointing at Object, which is at the root. For instance, when you write this:
public class MyClass extends Object {
Is exactly the same as this:
public class MyClass {
And if we have this:
public class MySubClass extends MyClass {
Then MySubClass extends from MyClass which extends from Object. It's a transitive inheritance relationship, and it occurs in only one direction: at no point in the hierarchy it will be possible that a single class extends from more than one class - that's why we say that in Java we have single-inheritance (as opposed to: multiple-inheritance.)
A inherits from Object and B inherits from A. So you have 3 levels of inheritance (2 explicit). There is no multiple inheritance here.
`Object`
    |
   `A`
    |
   `B`
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With