The difference between Classes, Objects, and Instances

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

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

16条回答
  •  终归单人心
    2020-11-22 06:35

    A class is basically a definition, and contains the object's code. An object is an instance of a class

    for example if you say

    String word = new String();
    

    the class is the String class, which describes the object (instance) word.

    When a class is declared, no memory is allocated so class is just a template.

    When the object of the class is declared, memory is allocated.

提交回复
热议问题