Object Class is the parent class of all the classes in Java by default. In other words it is the top most class of the Java.
We already know that the sub class object reference can be assigned to the super class object. As Object Class is the Super Class of all the classes in Java, we can assign the object reference of any class in Java to the object of the Object Class.
Lets implement Assigning the object reference of any Class to the object of Object Class -
1. Launch Eclipse IDE, create a Java Project 'Project 31' as shown below -
2. Create a Class 'ClassOne' with one( ) method as shown below -
3. Create a Class 'ClassTwo' with main( ) method as shown below -
4. Create an object for 'ClassOne' class as shown below -
5. Create an object for the parent of all classes in Java i.e. Object Class as shown below -
6. As Object Class is the superclass of all the Classes in Java, we can assign the object reference of ClassOne Class to the object variable of the Object Class as shown below -
Hence we can assign the object reference of any class to the object of the Object Class.
Please comment below to feedback or ask questions.