---
title: "Object Class in Java"  
description: "By Default, the Object class is the parent class of all the classes in java or we say, it is the topmost class of java."  
author: "Anupam Mishra"  
published: 2015-11-09  
updated: 2017-12-14  
canonical: https://www.mindstick.com/articles/11908/object-class-in-java  
category: "java"  
tags: ["java", "j2ee"]  
reading_time: 1 minute  

---

# Object Class in Java

The [Object class](https://www.mindstick.com/blog/539/object-class-in-c-sharp) is useful if you want to refer any object whose type you don't know. Note that parent class [reference](https://www.mindstick.com/forum/34619/call-by-value-and-call-by-reference) [variable](https://www.mindstick.com/blog/11493/what-is-a-variable) can refer the [child class](https://www.mindstick.com/forum/159389/how-to-remove-child-class-from-active-div) object, know as upcasting.

Now ,we taken an example, there is getObject() method that returns an object but it can be of any type like [Employee](https://www.mindstick.com/articles/178134/how-to-write-the-best-welcome-letter-for-new-employees),[Student](https://yourviews.mindstick.com/view/84686/importance-of-brahmacharya-in-student-life) etc, we can use Object class reference to refer that object. For example:

Object obj=getObject();//we don't what object would be returned from this method

The Object class provides some common behaviours to all the [objects](https://www.mindstick.com/forum/159749/what-are-data-transfer-objects-dtos-and-why-are-they-used-in-api-development) such as object can be compared, object can be cloned, object can be notified etc.

\

For Example: [Object Cloning](https://www.mindstick.com/interview/2374/what-is-object-cloning-in-java)**\**

\

The object cloning is used to create exact copy of an object. \
For this purpose, clone() method of Object class is used to clone an object. The clone() method saves the extra [processing](https://www.mindstick.com/blog/254/background-processing-in-android) task for creating the exact copy of an object.\

```
class Student  implements Cloneable{  int rollno;  String name;    Student(int rollno,String name){  this.rollno=rollno;  this.name=name;  }  public Object clone()throws CloneNotSupportedException{  return super.clone();  }  public static void main(String args[]){  try{  Student s1=new Student(101,"anupam");  Student s2=(Student)s1.clone();    System.out.println(s1.rollno+" "+s1.name);  System.out.println(s2.rollno+" "+s2.name);  }catch(CloneNotSupportedException c){}  }  }  
```

> \
>
> Output: 101 anupam \
> 101 anupam

\
\

---

Original Source: https://www.mindstick.com/articles/11908/object-class-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
