Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If System s = null then what will the output of below [duplicate]

Tags:

java

system

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?

like image 421
Arat Kumar rana Avatar asked May 23 '15 15:05

Arat Kumar rana


1 Answers

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.

like image 192
Mark McKenna Avatar answered Nov 14 '22 23:11

Mark McKenna