I'm trying to understand how System.out can invoke println(). All the searches say System.out is an instance of PrintStream class therefore it can invoke a method in that class.
BUT...
When I try to duplicate this with the following a NullPointerException results.
public class Main {
public static void main(String[] args){
Tasker.calc.add(1, 2);
}
}
class Tasker{
static Calc calc;
}
class Calc {
public void add(int x, int y){
System.out.println(x+y);
}
}
Isn't Tasker.calc a similar instance of Calc? How is System.out not a NullPointerException?
To be clear, this is not a question about NullPointerException... this is a question about why System.out doesn't require initialization.
Thanks a bunch!