• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Java extends Object,SuperClass?

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks sam, actually i had doubt regarding this. just i want to clear my doubt.
 
I am mighty! And this is a mighty small ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic