• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Inheritance

 
Adarsh Raj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if every class in java automatically extends the base class Object, how is it possible to write such as

concerning the fact that, java allows at a time only one class to be extended.

Adz
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adarsh Raj wrote:if every class in java automatically extends the base class Object, how is it possible to write such as

concerning the fact that, java allows at a time only one class to be extended.

Adz


Its like SomeClass extends AnotherClass and AnotherClass extends Object class. So at a time one class is extending single class. If you do not extend any class compiler inherits Object class by default.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pawan is right. SomeClass has a super type of Object but not as the direct super class.
 
nick kaushik
Ranch Hand
Posts: 48
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
compiler first checks whether you have inherited a class or not...if you haven't then it puts the extend statement of the base class itself....
 
Adarsh Raj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to everyone who replied. I got the answer i was looking for.

Adz
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adarsh Raj wrote:Thanks to everyone who replied. I got the answer i was looking for.

Adz
I think you got the right answer too!

And welcome to JavaRanch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic