Here are 4 MCQs on the fundamentals of Java:
1. Which of the following is NOT a valid Java keyword?
a) static
b) interface
c) unsigned
d) abstract
2. What is the correct way to declare a constant in Java?
a) final int MAX_VALUE = 100;
b) const int MAX_VALUE = 100;
c) static int MAX_VALUE = 100;
d) int MAX_VALUE = 100;
3. Which Java access modifier provides the highest level of restriction (most private)?
a) protected
b) public
c) default (package-private)
d) private
4. What will be the output of the following Java code snippet?
public class MyClass {
public static void main(String[] args) {
int x = 5;
System.out.println(x++);
}
}
a) 5
b) 6
c) Compilation Error
d) Runtime Error
Answers:
* c) unsigned
* a) final int MAX_VALUE = 100;
* d) private
* a) 5