I was checking System.out.println to understand composition of Java and i tried to make a similar of it like this;
FakeSystem class
public class FakeSystem {
public final static Print out = null;
}
Print class
public class Print {
public void print(String text){
System.out.println(text);
}
}
Main class
public class Main {
public static void main(String[] args) {
FakeSystem.out.print("my text");
}
}
It gives NullPointerException when i do this but it has null when i check "out" variable of original System class at java.lang package. It gives "my text" output when i change "out" variable to this;
public final static Print out = new Print();
I wanna understand why doesn't it work when i make it null.