Java Multiple Choice Questions (MCQs)
1. Core Java
Q1. Which of the following is true about the final keyword in Java?
- A) A
finalclass can be subclassed. - B) A
finalmethod can be overridden. - C) A
finalvariable's value cannot be changed once assigned. - D)
finalis used to define interfaces.
Answer: C. A final variable acts as a constant and its value cannot be modified once initialized.
Q2. What is the size of int data type in Java?
- A) 16 bits
- B) 32 bits
- C) 64 bits
- D) Depends on execution environment
Answer: B. In Java, int is always 32 bits (4 bytes) regardless of the underlying platform architecture.
2. Object-Oriented Programming
Q3. Which of these cannot be used for a variable name in Java?
- A) identifier & keyword
- B) identifier
- C) keyword
- D) none of the mentioned
Answer: C. Keywords are reserved words in Java and cannot be used as variable names.
Q4. What is the process of defining more than one method in a class with the same name but different parameters?
- A) Method overriding
- B) Method overloading
- C) Method hiding
- D) Encapsulation
Answer: B. Method overloading allows multiple methods to have the same name but different parameter lists.
3. Collections & Generics
Q5. Which collection class allows you to associate its elements with key values, and does not allow duplicate keys?
- A)
java.util.Set - B)
java.util.List - C)
java.util.Map - D)
java.util.Queue
Answer: C. The Map interface maps keys to values, and a map cannot contain duplicate keys.