123k views
0 votes
Which of the following variable declaration would NOT compile in a java program?

(a) int var;
(b) int VAR;
(c) int var1;
(d) int var_1;
(e) int 1_var;.

User Robhudson
by
8.2k points

1 Answer

3 votes

Final answer:

The variable declaration that would not compile in Java is 'int 1_var;' because it begins with a number, violating Java's variable naming conventions.

Step-by-step explanation:

In Java, variable names must follow certain rules for the code to compile correctly. A variable name can begin with a letter, an underscore (_), or a dollar sign ($). However, it cannot start with a number. Therefore, out of the options provided, the only variable declaration that would NOT compile in a Java program is (e) int 1_var;. This is because it begins with a number, which is against Java's variable naming rules. The rest of the options are all valid Java variable names, as they start with either a letter or an underscore.

User Simon Fischer
by
8.2k points