Here are 10 essential multiple-choice questions on Java Basics and Identifiers, covering key concepts with practical examples.
Question 1
What is the correct way to declare a Java main method?
public static void Main(String[] args)
public void main(String args)
public static void main(String[] args)
private static void main(String args[])
Question 2
Which of the following is NOT a valid Java identifier?
_myVar
2ndVariable
$amount
myVariable123
Question 3
What is the output of the following Java program?
public class Geeks {
public static void main(String[] args) {
int number = 10;
System.out.println(Number);
}
}
10
Compilation Error
Runtime Error
Undefined Behavior
Question 6
What will be the output of the following Java snippet?
public class Geeks {
static int $count = 5;
public static void main(String[] args) {
System.out.println($count);
}
}
5
Compilation Error
Runtime Error
Undefined Behavior
Question 7
Which statement about Java identifiers is FALSE?
Identifiers are case-sensitive
Identifiers can contain spaces
Identifiers can begin with _ or $
Identifiers cannot be Java keywords
Question 8
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
int my_var = 20;
System.out.println(my_var);
}
}
20
Compilation Error
Runtime Error
Undefined Behavior
Question 9
What will happen if you use a Java keyword as an identifier?
Compilation Error
No Error
Runtime Error
The keyword will be ignored
Question 10
Which of the following is a valid identifier in Java?
123abc
@value
myVariable
void
There are 10 questions to complete.