Multiple choice technology programming languages

Which of these are not legal identifiers. Select all the correct answers.

  1. 1alpha

  2. _abcd

  3. xy+abc

  4. transient

  5. account-num

  6. very_long_name

Reveal answer Fill a bubble to check yourself
A,C,D,E Correct answer
Explanation

Legal Java identifiers cannot start with a digit (A: 1alpha), cannot contain operators like + (C: xy+abc), cannot be keywords (D: transient is reserved), and cannot contain hyphens (E: account-num). Options B (_abcd) and F (very_long_name) are legal.

AI explanation

To answer this question, we need to understand the rules for legal identifiers in programming languages.

In general, legal identifiers must follow these rules:

  1. They can only contain letters (both uppercase and lowercase), digits, and underscores.
  2. They cannot start with a digit.
  3. They cannot contain special characters such as +, -, *, /, etc.

Let's go through each option to determine which ones are not legal identifiers:

A. 1alpha - This option is not a legal identifier because it starts with a digit.

B. _abcd - This option is a legal identifier because it starts with an underscore and contains only letters, digits, and underscores.

C. xy+abc - This option is not a legal identifier because it contains the special character '+'.

D. transient - This option is a legal identifier because it contains only letters.

E. account-num - This option is not a legal identifier because it contains the hyphen '-'.

F. very_long_name - This option is a legal identifier because it contains only letters, and underscores.

Therefore, the correct answers are A, C, D, and E.