Java - is `null` an instance of `object`?

前端 未结 7 1464
清酒与你
清酒与你 2021-01-07 16:36

I read that null isn\'t an instanceof anything, but on the other hand that everything in Java extends Object class.

7条回答
  •  Happy的楠姐
    2021-01-07 16:57

    Null means that you don't have a reference to an object.

    Object o = null;
    

    o is a reference but there is no object referenced and no memory allocated for it.

    o = new Object();
    

    o is still a reference and holds the adress where the object is located in memory

提交回复
热议问题