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 only the top level class

 
T sandya
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
why object class only the top level class for all classes?
what is the special in that?
why object class only they make as root class instead of making some other classes as root classes?

please discuss your opinions.

Regards,
Sandya.
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i think the below shown link can help you to understand why object class is the top level class,although there may be many reasons but some can be explained as follows...


http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter04/Object.html


i hope it helps you.
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think this below shown link will make you more clear..


http://journals.ecs.soton.ac.uk/java/tutorial/java/javaOO/objectclass.html
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java designers wanted to make certain functionality available to absolutely all objects, so they created an Object class and made everything inherit it.

Not all languages are like this. C++, for instance, has no common superclass. Hence there are no data or methods shared by all C++ classes.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The Object class is the only top level class in Java because as already posted above, there must be some common functionality inherent in all objects, one such commonly used functionality is String representation of the object.
Also one another important aspect of using a single top level class is to
facilitate the use of Single Rooted Hierarchy.
Besides its several purposes, one important feature obtained is that you can use the generic Object in your code and decide the actual (required) type of object dynamically during runtime.

You can also find out more reasons by further reading.
Hope it helps
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There must be some common functionality inherent in all objects ,,,


Don't forget that was a decision of the language designer, not a cosmic truth. You can find other languages that don't have a common ancestor class. That doesn't matter much in Java but one day you'll get bored with Java and try the Next Big Language that might not agree.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also see The singly rooted hierarchy topic from Eckel's Thinking in Java.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic