• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java extends Object,SuperClass?  RSS feed

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,


Example,


Rancher extends Object class implicitly . if Rancher extends A class then, it likely extends both Object and A class ?

please somebody explain about this
 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Rancher extends A, and A either implicitly or explicitly extends Object, Rancher indirectly extends Object. Every class in Java extends Object.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moojid Hamid wrote:If Rancher extends A, and A either implicitly or explicitly extends Object


Well , But already Rancher class extends Object implicitly right ? what happend to that ? compiler will just replace that with A class ? please i need some more clarification .
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep the compiler will just replace it with class A or whatever the compiler wants to do - I would not really bother with how it does it.

What it does is important,

Rancher class now extends A. Since in java a class can only extend one class at a time (multiple inheritance is not allowed) Rancher no longer (directly) extends object.

Class A on the other hand does not extends any class so it implicitly must extend Object. Rancher extends A so it indirectly extends Object. (Multilevel inheritance is permitted in Java).

The indirect extension does have one important implication.
Lets say the class A overrides the equals() method of the object class. Then the Rancher class will always use this over ridden equals method (unless it over rides it itself) instead of the equals method of the Object class.

Whats the context of the question? Knowing the context would help give you a better answer...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sam, actually i had doubt regarding this. just i want to clear my doubt.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!