What is a class, an object and an instance in Java?
In java, the objects are spawned on heap memory. These require reference to be pointed and used in our application. The reference has the memory location of the object with which we can use the objects in our application. A reference in short is nothing but a name of the variable which stores the address of the object instantiated on a memory location.
An instance
is a general term for object
. FYI, Object
is a class.
For Example,
Class A{
}
A ref = new A();
For the above code snippet, ref is the reference for an object of class A generated on heap.