In Java compiler,The print in System.out.print can be defined as identifier or Keyword? [duplicate]

蹲街弑〆低调 提交于 2019-12-14 03:32:44

问题


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");
        }
}

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/29823840/in-java-compiler-the-print-in-system-out-print-can-be-defined-as-identifier-or-k

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!