search

Home  >  Q&A  >  body text

java import problem

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:

迷茫迷茫2754 days ago530

reply all(1)I'll reply

  • 阿神

    阿神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;
    
       

    reply
    0
  • Cancelreply