Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a class extend two classes in Java?

If Java can only extend one class, and every class extends java.lang.Object, how can it extend another class? And how come every class doesn't have written extends Object?

like image 589
splitgames Avatar asked Nov 15 '25 09:11

splitgames


1 Answers

If java can only extend one class, and every class extends java.lang.Object, how can it extend another class?

When you say A extends B then it means that A extends B and B extends Object. One class can inherit from another which can inherit from another and at the top of the chain is java.lang.Object. Java doesn't support multiple inheritance , but supports multi-level inheritance.

how come every class doesn't have written "extends Object" ?

All classes extend Object implicitly , so it will be redundant coding.

like image 148
AllTooSir Avatar answered Nov 17 '25 08:11

AllTooSir



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!