Which of the following is a legal Java identifier?

Which of the following is a legal Java identifier?

a) i
b) class
c) ilikeclass!
d) idon’tlikeclass
e) i-like-class


Answer:  a.

Explanation:  Java identifiers cannot have the characters “!”, “‘” or “-” in them making answer c, d and e wrong.  The word “class” is a reserved word in Java and cannot be used as an identifier.  The identifier “i” is perfectly legal although it is not necessarily a good identifier since it is not descriptive of its use.


Java

Learn More Multiple Choice Question :