Given: 35. String #name = “Jane Doe”; 36.int$age=24; 37. Double_height = 123.5; 38. double~temp = 37.5; Which two are true? (Choose two.)
-
Line 35 will not compile.
-
Line 36 will not compile
-
Line 37 will not compile.
-
Line 38 will not compile.
Java identifiers must start with a letter, underscore, or dollar sign, and can only contain letters, digits, underscore, and dollar sign. The # and ~ characters are invalid in identifier names, so lines 35 and 38 fail to compile.
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) Line 35 will not compile. In Java, when declaring a variable, the variable name must start with a letter, underscore, or a dollar sign. In this case, the variable name starts with a pound sign (#), which is not a valid character. Therefore, Line 35 will not compile.
Option B) Line 36 will not compile. In Java, the variable type should come before the variable name. In this case, the variable type is specified as "int$", which is not a valid type declaration. Therefore, Line 36 will not compile.
Option C) Line 37 will not compile. Line 37 declares a variable named "Double_height" of type Double. The variable name starts with an uppercase letter, which is allowed in Java, but it is considered a bad practice. However, the code will compile and run without any issues. Therefore, Line 37 will compile.
Option D) Line 38 will not compile. In Java, the variable name cannot contain special characters like "~". Therefore, Line 38 will not compile.
The correct answer is A and D. Line 35 will not compile because the variable name starts with a pound sign (#), and Line 38 will not compile because the variable name contains a special character (~).