• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Why "Object" class

 
Ranch Hand
Posts: 8934
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can anyone explain me the need for cosmic superclass "Object"?
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe to ensure that all objects have those 11 methods (wait, notify,...)
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It also allows the creation of methods that can take any object as a parameter. For example, the Collection classes can hold any object because their methods take an Object as a parameter.
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think these two pretty much sum it up.
Having a common ancestor ensures that all classes will have some base functionality (either by the inherited methods or by providing a new implementation of these methods).
This common ancestry also goes to the second point in that any class can be cast to an Object and thus be more portable.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradeep,
What timothy says is exactly right.
To augument that, Think of how garbage collector works. GC invokes on the superclass object.
If you create an object of human named babu, after using the behaviours i.e after reference is lost, it has to be garbage collected. How does JVM knows what object(babu) to collect. But java has single rooted hierarchy, it knows that object babu is a subclass of Object, so i collect him as garbage using the object type handle.
Hope this wud help you
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!