Which of the following are not legal Java identifiers? Select 1 correct option. a goto Although not used, it's a reserved word. b unsigned It's not a reserved or keyword. c String Yes, it is valid. This is a valid statement: String String = "String"; d _xyz Can start with _ or $ e $_abc Can have _ or $.
Ans a. why not b??
In the option C, a class name "String" is used as an identifer. I had tried with others like Integer and code compiles. How java allows this.
Any specific reason why class name are been allowed to be used as identifiers.
Another way to think about this is that Java has several namespaces and the same isentifier can have a different meaning in each namespace.
For example, C can be a class name, a variable name, and a label name (used in break and continue), all at the same time. The Java compiler always knows which identifier dictionary to look in depending on the statement syntax.