This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object" Watch "object" New topic
Author

object

thinakaran thinakaran
Greenhorn

Joined: Mar 28, 2003
Posts: 8
why java having object class?
What is the use of that
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Because we don't want any orphan classes Every class in Java has Object as an ancestor. Certain methods vital to the VM and other classes are defined there. Such as wait() and notify() which are used to control access to other objects by multiple threads. Also the equals() and hashCode() methods which are important to collections backed by hashmaps. And of course, every debuggers favorite, the toString() method. There are others too, like clone(), finalize() and getClass() (which allows us to use the Reflection API to reveal fields and methods of a class). So, as you see, the granddaddy Object class plays an important role in every Java programmers life, whether he realizes it or not.
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

Here's one article that discusses the implications of having a single-rooted hierarchy of classes like Java does as opposed to C++, which doesn't.


Junilu - [How to Ask Questions] [How to Answer Questions]
 
jQuery in Action, 2nd edition
 
subject: object
 
Similar Threads
MultiDimenaional Array sort
WA #1.....word association
generics - why does this work?
Thread and Object
Array