Identifer versus keyword

前端 未结 5 1569
北海茫月
北海茫月 2021-02-16 00:05

I read in the book for OCJP for Java6 the part with assertions. I reached the part where it gives me an overview of how the compiler reacts if the word \'assert\' is used as key

5条回答
  •  粉色の甜心
    2021-02-16 00:31

    Keywords are reserved words like new,static,public,if,else,..

    An identifier can be a name of any variable.

    int age = 26;
    

    "age" here is an identifier, while int is a reserved word.

    The following example won't compile:

    String static = "hello";
    int public = 4;
    

    you can't do this because "static" and "public" are keywords, that in this case are being used as identifiers, which is not allowed.

提交回复
热议问题