• 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

Why extend Object??

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys/gals,
Can anyone give me a good reason as to why you'd want to extend Object? I've seen some examples that do this, but don't all classes end up inherting from Object anyway? So why would one want to do this?
/rick
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can only think : "For clarity purposes"
Anybody else ...
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the following code:

We don't explicitely extend Object. When you compile (with javac) and decompile (with javap), what you get is the following:

So you can see that the compiler adds the "extends java.lang.Object" and the default constructor by itself.
So, the compiler does some job for you but it doesn't hurt to do it yourself... for clarity purposes...
 
Rick Salsa
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Brian and Valentin
That's what I thought. So it is safe to say that it doesn't provide any extra functionality to us. Mostly for clarity purposes...
/rick
 
reply
    Bookmark Topic Watch Topic
  • New Topic