Inheritance without word "extends" in Java

Is it possible to inherit a class without using the extends keyword in Java?

+3


source to share


3 answers


Yes. Each class extends Object

whether you add extends Object

to the declaration or not.

There are also anonymous classes like



Foo foo = new Foo(){
    // some method implemented in here.
};

      

which can extend the class without extends

.

+8


source


Yes, each class extends Object

by default without declaration.



+1


source


As stated in this thread, all classes extend from Object.

So it exists, however it is not something you can control without using the extends keyword. I don't think you will ever need to if you should perhaps discuss this particular situation.

+1


source







All Articles