• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic