Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Object class is parent of all

 
Kartik Patel
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone let me know why Object class in java is parent of any object gets created.
 
Sidd Kulk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch!!

Java is an object oriented language and hence stresses reusability, flexibility and extensibility. Java forces the coders to code behaviour using classes(or types). Each class that a coder creates, needs to know the object oriented principles. It is not possible(and would be ludicrous) to code the standard code that makes a class understand object orientation in each and every class you form. OO practice tells us to use inheritence in case a common behaviour exists for an assortment of types. For this purpose, the Object class was made, with all the standard code, and methods required by each class. It has various methods like toString(), equals(), wait(), notify(), notifyAll() etc., which each class should have. For this, and probably few other purposes, the Object class was kept at the top of inheritence hierarchy, so that any new class would know that it has to follow OO rules and has a set of predefined methods.

Hope it helps.
Sid
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic