Examveda
Examveda

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.

This Question Belongs to Java Program >> Data Types And Variables

Join The Discussion

Related Questions on Data Types and Variables