Which of the following is an illegal identifier in Java?

Enhance your Java programming skills with our Introduction to Java Programming Test. Boost your confidence with our multiple choice questions, each complete with hints and explanations. Prepare for your exam success!

In Java, identifiers are names given to elements such as variables, methods, classes, and more. There are specific rules governing what constitutes a legal identifier. An identifier must begin with a letter (a-z or A-Z), a dollar sign ($), or an underscore (_). Following the first character, identifiers may include letters, digits (0-9), dollar signs, and underscores.

The choice that is an illegal identifier is "employee Salary." The issue here is that it contains a space between "employee" and "Salary." Spaces are not allowed in identifiers; this is a fundamental rule in Java syntax. When the compiler encounters this space, it cannot parse the name as a single, valid identifier.

In contrast, the other options are valid identifiers. "_conversion" begins with an underscore, which is permitted, and "$payRate" starts with a dollar sign, which is also valid. "address2" starts with a letter and follows the rules for identifiers without any spaces or invalid characters.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy