public class Main
{
public static void main(String []ar)
{
A m = new A();
System.out.println(m.getNull().getValue());
}
}
class A
{
A getNull()
{
return null;
}
static int getValue()
{
return 1;
}
}
I came across this question in an SCJP book. The code prints out 1 instead of an NPE as would be expected. Could somebody please explain the reason for the same?
It behaves as it should according to the Java Language Specification: