Why is object class the super class in Java?
Java classes (implicitly/explicitly) extends Object
for the following reasons:
native
. That way, all objects gets registered as a native object that the JVM can understand and execute. Don't forget that JVM is written in C++ (irrespective of the platform it's executed on).finalize
method is called by the JVM when the Object is not needed.The rest have been mentioned here already.
Off the top of my head
Defining 'Object' as the root class ensures the VM can rely upon the interface provided for utility methods such as equals, clone, hashcode etc
The Garbage collector can ensure anything that the user deemed reconcilable can be executed in the finalize method
The java program is essentially manipulation of
method and class.
The class inherit some properties on which there structure built up later.
Object is the basic class and all classes are subclass of Object.
It provides a template for all the derived objects that programmers create. The key functionalities that may be required for every user-defined object are readily available this way.
Object locking (For concurrency-problem resolution)
Cloning
To name the more important ones.
That is a good question. 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).
It's what we call the axiom of object-oriented programming in Java. Every single abstraction in your code is an object. It contains a few things that are applicable to every peace of information you use in your code:
equals
and hashCode
methods to establish an equality theory within the given abstraction (see corresponding javadoc);toString
to represent an object in human-readable (probably, only programmer-readable) format (because most of us still use displays and keyboards);getClass
to provide reflection capabilities on the given abstraction;If you learn Java, it is best for you to study the "Inheritance" section of whatever book you use and then try to answer this question yourself.