aryan :
What is the reason for the output? I know it prints Hello World
but don’t know why as it should give NullPointerException
.
public class Null
{
public static void greet()
{
System.out.println("Hello World");
}
public static void main(String[] args)
{
((Null)null).greet();
}
}
Code_Mode :
This is because greet()
is a static method. So
((Null)null).greet();
is equivalent to,
Null.greet()