Java Intermediate Quiz

Test your knowledge of Java programming

1. Which of these is not a Java access modifier?
Correct Answer: internal
Explanation: Java does not have an "internal" access modifier.
2. Which interface must be implemented to allow an object to be cloned?
Correct Answer: Cloneable
Explanation: Implementing the Cloneable interface allows the use of Object.clone().
3. Which of these is used for thread synchronization?
Correct Answer: synchronized
Explanation: The synchronized keyword ensures that only one thread can access a block/method at a time.
4. Which collection allows duplicate elements?
Correct Answer: List
Explanation: List allows duplicate elements; Set does not.
5. What is the size of int in Java?
Correct Answer: 32 bits
Explanation: In Java, an int is a 32-bit signed integer.
6. Which of these is not a Java keyword?
Correct Answer: include
Explanation: "include" is not a Java keyword; it is used in C/C++.
7. Which method is used to start a thread?
Correct Answer: start()
Explanation: start() method is used to begin execution of a thread.
8. What is the default value of a boolean variable?
Correct Answer: false
Explanation: The default value of a boolean in Java is false.
9. Which package contains the Random class?
Correct Answer: java.util
Explanation: Random class is part of java.util package.
10. Which of the following is a marker interface?
Correct Answer: Serializable
Explanation: A marker interface has no methods; Serializable is one example.
11. What is the output of 5/2 in Java?
Correct Answer: 2
Explanation: Integer division truncates the decimal part in Java.
12. Which class is the superclass of all wrapper classes?