Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

object  RSS feed

 
thinakaran thinakaran
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why java having object class?
What is the use of that
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Junilu Lacar
Sheriff
Posts: 11169
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!