Difference between Object and Instance in Java
Characteristics |
Object |
Instance |
---|---|---|
Definition |
object is runtime entity of a class. |
instance is single occurrence of a class. |
Creation |
Created during runtime using new keyword. |
Created when an object is instantiated using new keyword. |
Memory Allocation |
Occupies memory space based on class definition. |
Occupies memory space based on class definition. |
Purpose |
Represents a specific instance of a class. |
Represents a single occurrence or instantiation of a class. |
Identity |
Each object has a unique identity. |
Each instance has a unique identity within object. |
Usage |
The Objects can be used to call methods and access fields. |
The Instances are used to access methods and fields specific to that instance. |
Example |
Car my = new Car(); |
Person person01 = new Person(); |
Difference Between Object and Instance in Java
The object is an instance of a class. A class is like a blueprint or template that defines the properties and behavior of objects. When we create an object we are creating an instance of that class.
Contact Us