The top Class in the Java hierarchy i.e. 'Object Class' has the following methods -
As all the other classes in the Java are sub classes of Object Class, all the Classes in Java can access these methods using their objects.
Lets implement and find out where all the Classes of Java can access Object Class methods using their objects -
1. Launch Eclipse IDE, create a Java Project 'Project 32' as shown below -
2. Create a Java Class 'ClassOne' as shown below -
3. Create another Class 'ClassTwo' with main( ) method as shown below -
4. Create an object for Object Class as shown below -
5. Create an object for 'ClassOne' as shown below -
6. Now access any method of Object Class by entering dot '.' after the object of Object Class as shown below -
Observe that all the methods( ) of the Object Class are displayed as shown above.
7. In the similar manner enter dot '.' after the object of ClassOne Class as shown below -
Hence all the Classes in Java can access the methods( ) of Object Class as shown above.
Lets access the methods of Object Class using other Class objects and implement them in the next post.
Please comment below to feedback or ask questions.
No comments:
Post a Comment