Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why Object Class was chosen Parent to all java classes?

 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why Object Class was chosen Parent to all java classes?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it sounded like a good idea at the time
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java borrowed alot of ideas from Smalltalk. In Smalltalk everything is an object
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because every object in java is an umm.. object and all the properties and methods common to all objects are in the Object class
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I think the reason was, They designed a class named 'Object' which had a few really good methods and then they used the benefits of inheritance. So now whenever we define a class, we have a few methods from the Object class as well.

Can anybody out there, give a really good explaination about this. I think there is much much more than, what appears here.
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java it is important to understand what the definition of an object is.
An object is a class instance or an array

This definition is slightly different from that of SmallTalk, C++ and a host of other OO languages.

The reason this is significant is that Interfaces in Java are not considered Objects and therefore, we are allowed to implement more than one Interface while only extending only one direct Superclass. Other languages allow for inheritence from more than one superclass (multiple polymorphism),
in java this can only be achieved by abstract classes using other abstract classes.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider how nicely the single base class called Object works out for us. You can take any kind of object at all and store it in an Object variable or pass it to an Object parameter:

Lists and Maps and Sets and such can store any object because they are written this way.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic