Thursday 27 July 2017

When java doesn't support pointers why does it throws NullPointerException ?

ANS------------->
if we invoke method or variable on a reference variable that hold null value than NullPointerException will be thrown.




Date d=null;
d.getYear();  //throws NullPointerException 

Here the word pointer in NullPointerException is no related to c,c++ pointers. it with the English meaning that indicated method is called on reference variable that points to null points to null value.

Date d = null;
D= new Date();
d.getYear();  // no exception 

No comments:

Post a Comment