As to access the methods of PrintStram class an object must be created, so how the out variable is able to access those methods when it is assigned null.
public final static PrintStream out = null;
This is the declaration in System class.
I tried to write the similar code but then it gives NullPointerException. My code is given below.
class First{
public void display(){
System.out.println("Hello");
}
}
class Second{
public final static First s1=null;
}
public class Third{
public static void main(String[] args) {
Second.s1.display();
}
}
To make this code run i will have to make either display method static or define s1 as-
public final static First s1=new First();