top button
Flag Notify
Site Registration

Reason behind the Object class

+2 votes

Why in the Obejct class parent for all classes in Java. what is the reasoning behind this.

posted Jun 23, 2013 by Vikalp Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Java chose to make a single class be the ultimate parent class for everything so that there is an easy way to pass around any arbitrary object, without needing to know its type (i.e. you can use the declared type of Object to refer to every single item in the type system, even primitives using their wrapper classes). However, there are OOP languages such as C++ where there is no universal base class as in Java. Another benefit to having a universal base class is that logic dealing with the superclass does not have to be special cased for top-level classes (with the exception of the universal base class, Object, itself).

answer Jun 23, 2013 by Salil Agrawal