
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Root Class in Java
The Object class of the java.lang package is the root class in Java i.e. It is the super class of every user-defined/predefined class n Java. All objects, including arrays, implement the methods of this class.
The reason for this is to have common functionalities such as synchronization, garbage collection, collection support, object cloning for all objects in Java.
The class named Class of java.lang package provides a method named getSuperclass() this method returns the Class representing the superclass of the current Class.
So, Create a sample concrete class and try to get the name of its super class using this method.
Example
public class Sample { public static void main(String args[]) { Sample obj = new Sample (); Class cls = obj.getClass().getSuperclass(); System.out.println(cls.getName()); } }
Output
Since the Object class is the super class of all classes it displays the name of the object class as shown below.
java.lang.Object
Advertisements