Which of the following is not a valid identifier for a Java variable?
A. my_var
B. _myVar
C. 3rdVar
D. $var
Answer: Option C
Solution(By Examveda Team)
The correct answer is Option C: 3rdVar.In Java, variable identifiers (names) must follow certain rules:
They can only start with a letter (A-Z or a-z), underscore (_), or dollar sign ($).
The subsequent characters can be letters, digits (0-9), underscores, or dollar signs.
They cannot be a Java keyword (reserved word).
Option A (my_var), Option B (_myVar), and Option D ($var) all follow these rules and are valid variable identifiers.
Option C (3rdVar) is not valid because it starts with a digit, which is not allowed for variable names in Java.
Related Questions on Data Types and Variables
What is the maximum value that can be stored in a byte variable in Java?
A. 127
B. 255
C. 32767
D. 64
What is the default value of an int variable in Java if it's not explicitly initialized?
A. 0
B. 1
C. -1
D. Null
Which of the following is not a valid identifier for a Java variable?
A. my_var
B. _myVar
C. 3rdVar
D. $var
Join The Discussion