The difference between Classes, Objects, and Instances

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

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

16条回答
  •  鱼传尺愫
    2020-11-22 06:33

    Class

    • It has logical existence, i.e. no memory space is allocated when it is created.

    • It is a set of objects.

    • A class may be regarded as a blueprint to create objects.

      • It is created using class keyword

      • A class defines the methods and data members that will be possessed by Objects.


    Object

    • It has physical existence, i.e. memory space is allocated when it is created.

    • It is an instance of a class.

    • An object is a unique entity which contains data members and member functions together in OOP language.

      • It is created using new keyword

      • An object specifies the implementations of the methods and the values that will be possessed by the data members in the class.

提交回复
热议问题