Which of these are not legal identifiers. Select all the correct answers.
-
1alpha
-
_abcd
-
xy+abc
-
transient
-
account-num
-
very_long_name
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.
To answer this question, we need to understand the rules for legal identifiers in programming languages.
In general, legal identifiers must follow these rules:
- They can only contain letters (both uppercase and lowercase), digits, and underscores.
- They cannot start with a digit.
- 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.