20 Basic Java Multiple Choice Questions (MCQs) with Answers
1. Which of the following is not a Java keyword?
A. class B. interface C. extends D. implement
>> Answer: D. implement
Explanation: The correct keyword is "implements", not "implement".
2. Which method is the entry point of a Java program?
A. start() B. run() C. main() D. init()
>> Answer: C. main()
Explanation: public static void main(String[] args) is the entry point.
3. What is the size of an int in Java?
A. 8 bit B. 16 bit C. 32 bit D. 64 bit
>> Answer: C. 32 bit
Explanation: An int in Java is always 32 bits (4 bytes).
4. Which of the following is used to create an object in Java?
A. malloc B. new C. alloc D. create
>> Answer: B. new
Explanation: Java uses new keyword to create objects.
5. Which of these is not a primitive data type in Java?
A. int B. byte C. String D. double
>> Answer: C. String
Explanation: String is an object, not a primitive type.
6. Which keyword is used to inherit a class in Java?
A. implement B. inherits C. extends D. override
>> Answer: C. extends
7. What is the default value of a boolean variable in Java?
A. true B. false C. 0 D. null
>> Answer: B. false
8. What will be the result of 5 + 2 + "Java"?
A. 7Java B. 52Java C. Java52 D. Java7
>> Answer: A. 7Java
Explanation: Addition is left to right. First 5+2=7, then 7+"Java" becomes "7Java".
9. Which keyword prevents inheritance of a class?
A. static B. final C. constant D. protected
>> Answer: B. final
10. Which of the following is not a valid access modifier?
A. public B. private C. protected D. external
>> Answer: D. external
11. Which of these is not a loop in Java?
A. for B. while C. repeat D. do-while
>> Answer: C. repeat
12. Which collection class allows duplicate elements?
A. Set B. Map C. List D. TreeSet
>> Answer: C. List
13. What does JVM stand for?
A. Java Virtual Memory B. Java Verified Machine
C. Java Virtual Machine D. Java Variable Method
>> Answer: C. Java Virtual Machine
14. Which package contains Scanner class?
A. [Link] B. [Link] C. [Link] D. [Link]
>> Answer: A. [Link]
15. Which operator is used for comparison in Java?
A. = B. == C. := D. !==
>> Answer: B. ==
16. Which method is used to compare two strings in Java?
A. equals() B. == C. compare() D. match()
>> Answer: A. equals()
17. What is the result of true && false in Java?
A. true B. false C. 1 D. error
>> Answer: B. false
18. Which exception is thrown when dividing by zero in Java (int)?
A. NullPointerException B. ArithmeticException
C. IOException D. NumberFormatException
>> Answer: B. ArithmeticException
19. Which method is used to get the length of an array?
A. [Link]() B. [Link]() C. [Link] D. [Link]()
>> Answer: C. [Link]
20. Java is a:
A. Compiled language only B. Interpreted language only
C. Both compiled and interpreted D. None of the above
>> Answer: C. Both compiled and interpreted
Explanation: Java code is compiled to bytecode, then interpreted by the JVM.