The difference between Classes, Objects, and Instances

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

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

16条回答
  •  不要未来只要你来
    2020-11-22 06:11

    Class is Data Type,You use this type to create object.

    • Instance is Logical but object is Physical means occupies some memory.

    • We can create an instance for abstract class as well as for interface, but we cannot create an
      object for those.

    • Object is instance of class and instance means representative of class i.e object.

    • Instance refers to Reference of an object.

    • Object is actually pointing to memory address of that instance.

    • You can’t pass instance over the layers but you can pass the object over the layers

    • You can’t store an instance but you can store an object

    • A single object can have more than one instance.

    • Instance will have the both class definition and the object definition where as in object it will have only the object definition.

    Syntax of Object:

     Classname var=new Classname();
    

    But for instance creation it returns only a pointer refering to an object, syntax is :

     Classname varname;
    

提交回复
热议问题