Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance without "extends" keyword in Java

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

like image 272
Sruthi Mohan Avatar asked Jan 22 '26 12:01

Sruthi Mohan


2 Answers

Yes. Every class extends Object, whether you add extends Object to the declaration or not.

There are also anonymous classes, such as

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

which can extend a class without extends.

like image 53
Dawood ibn Kareem Avatar answered Jan 24 '26 03:01

Dawood ibn Kareem


Yes, Each class extend the Object by default without declaration.

like image 32
biezhihua Avatar answered Jan 24 '26 04:01

biezhihua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!