Yes, there is a difference, because they are not calling the same method.
Assuming the second statement actually compile, it means that the println("Hello World")
call is for a method that is either:
- defined in your class
- inherited from a super class
- a default method inherited from an interface (Java 8+)
- statically imported1
Now, the local/inherited/imported println(String s)
method could just have been implemented to call System.out.println(s)
, which would make it behave the same as the direct call to System.out.println(s)
, but that's different.
1) Since you cannot statically import java.lang.System.out.println()
(it is not a static method), it would have to be statically imported from some other class.