5

I have the below code.

public static void main(String args[])
  {
    System s = null;
    s.out.println("Hello");
  }

I don't understand why the output is Hello though s is null. Could anyone help me to understand this?

Arat Kumar rana
  • 187
  • 1
  • 5
  • 19

1 Answers1

6

System.out is a static member of the type System. This means that it doesn't require an instance to resolve; it only needs to know the type of s which is known to be System.

Being able to write s.out is just a convenience for System.out; most IDEs will throw a warning on this code.

Mark McKenna
  • 2,857
  • 1
  • 17
  • 17