What is null in Java?

后端 未结 14 1378
陌清茗
陌清茗 2020-11-21 20:49

What is null?

Is null an instance of anything?

What set does null belong to?

How is it represented in the me

14条回答
  •  醉酒成梦
    2020-11-21 21:14

    There are two major categories of types in Java: primitive and reference. Variables declared of a primitive type store values; variables declared of a reference type store references.

    String x = null;
    

    In this case, the initialization statement declares a variables “x”. “x” stores String reference. It is null here. First of all, null is not a valid object instance, so there is no memory allocated for it. It is simply a value that indicates that the object reference is not currently referring to an object.

提交回复
热议问题