The difference between Classes, Objects, and Instances

前端 未结 16 1766
耶瑟儿~
耶瑟儿~ 2020-11-22 05:32

What is a class, an object and an instance in Java?

16条回答
  •  既然无缘
    2020-11-22 06:11

    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.

提交回复
热议问题