In Java compiler,The print in System.out.print can

2019-09-22 05:31发布

I have studied about java which have listed 50 Java keywords. There is a homework of Lex, the goal is to recognize the word is keywords, IDs, symbols, operators. But there is one more little problem is the code below, is print in System.out.print() an ID or keyword?

 public class HelloWorld {
    public static int add(int a, int b) {
    return a + b;
    }
    public static void main(String[] args) {
        int c;
        int a = 5;
        c = add(a, 10);
        if (c > 10)
            System.out.print("c = " + -c);
        else
            System.out.print(c);
        System.out.print("Hello World");
        }
}

2条回答
Fickle 薄情
2楼-- · 2019-09-22 06:13

print is the name of a method in the java.io.PrintStream class, hence an ID. Keywords are those which generally turn blue or another colour when you type them in most IDEs.

For more information: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html

查看更多
神经病院院长
3楼-- · 2019-09-22 06:30

System is a final class from java.lang package.
out is the reference of PrintStream class and a static member of System class.
print is a method of PrintStream class.

//the System class belongs to java.lang package
class System {
  public static final PrintStream out;
  //...
}

//the Prinstream class belongs to java.io package
class PrintStream{
public void print();
//...
}

Have a look at this too.. https://docs.oracle.com/javase/7/docs/api/java/lang/System.html

查看更多
登录 后发表回答