Why does Java have a “NullPointerException” when there are no pointers in Java?

前端 未结 6 1433
不思量自难忘°
不思量自难忘° 2020-12-06 01:23

Why do I get an exception called NullPointerException if in Java there is no such concept as a pointer?

6条回答
  •  被撕碎了的回忆
    2020-12-06 01:49

    Because all the variables(on RHS of assignment) you declare are references to some objects in heap space. If a reference is not pointing any where then on accessing of that variable throws nullpointerexception.

提交回复
热议问题