import java.lang.System.out;//error
Why is the above statement at the beginning of the program wrong?
The following sentence is correct regardless of whether it has static or not. Why is this?
import static java.lang.System.*;
as the picture shows:
阿神2017-05-17 10:01:25
First you need to understand the newly added feature in 1.5 called static import
The so-called static import simply means importing static variables and methods
The format is import static package name.class name.static property|static method
Let me show you the source code: out is a static variable modified with static, so if you don’t add static when importing the package, an error will be reported
The System class only has static-modified properties or methods, so you don’t need to add static.
public final static PrintStream out = null;