Java MCQ SET-1
1. Which OOP principle is violated if a subclass overrides a method and
throws a broader checked exception than the superclass method?
A) Encapsulation
B) Polymorphism
C) Liskov Substitution Principle
D) Abstraction
2. What happens if a class implements two interfaces that contain default
methods with the same signature?
A) JVM selects one automatically
B) Compilation error unless overridden
C) Runtime exception
D) Both methods are executed
3. Which memory area of JVM stores class metadata?
A) Heap
B) Stack
C) Method Area
D) Program Counter
4. What is the default value of an object reference in Java?
A) 0
B) undefined
C) null
D) garbage
5. Which component of JVM is responsible for loading class files?
A) Execution Engine
B) Garbage Collector
C) Class Loader
D) JIT Compiler
6. What is the output?
class Test {
int x = 10;
Test() {
[Link](x);
}
{
x = 20;
}
public static void main(String[] args) {
new Test();
}
}
A) 10
B) 20
C) 0
D) Compilation error
7. What will be the output?
class Test {
public static void main(String[] args) {
String s1 = "Java";
String s2 = "Java";
[Link](s1 == s2);
}
}
A) true
B) false
C) Compilation error
D) Runtime exception
8. What happens here?
class Test {
public static void main(String[] args) {
Integer a = 127;
Integer b = 127;
[Link](a == b);
}
}
A) true
B) false
C) Compilation error
D) Runtime exception
9. What happens if we run this?
class Test {
static {
[Link]("Static Block");
}
public static void main(String[] args) {
[Link]("Main Method");
}
}
A) Main Method
B) Static Block
C) Static Block then Main Method
D) Compilation error
10. Which of the following best describes runtime polymorphism?
A) Method overloading
B) Method overriding
C) Constructor overloading
D) Operator overloading
11. Which of the following is TRUE about JVM?
A) JVM converts Java source code directly into machine code
B) JVM executes bytecode
C) JVM is platform dependent
D) JVM compiles Java into C++
12. Where are static variables stored?
A) Stack
B) Heap
C) Method Area
D) Native Method Stack
13. Which reference type is eligible for garbage collection?
A) Strong reference
B) Weak reference
C) Active reference
D) Static reference
14. What happens here?
class Test {
static {
[Link]("Static Block");
[Link](0);
}
public static void main(String[] args) {
[Link]("Main Method");
}
}
A) Static Block
B) Main Method
C) Static Block then Main Method
D) Nothing prints
15. What will be the output?
class Test {
public static void main(String[] args) {
String s1 = "Java";
String s2 = new String("Java").intern();
[Link](s1 == s2);
}
}
A) true
B) false
C) Compilation error
D) Runtime exception
16. What happens here?
class Test {
static int x = 10;
static {
x = x + 5;
}
static {
x = x * 2;
}
public static void main(String[] args) {
[Link](x);
}
}
A) 10
B) 15
C) 30
D) 20
17. What is the role of JIT compiler?
A) Converts Java to bytecode
B) Converts bytecode to native code at runtime
C) Loads classes
D) Manages heap
18. Which of the following statements about Garbage Collection is correct?
A) It guarantees object destruction immediately
B) It frees stack memory
C) It reclaims unreachable heap objects
D) It runs only once
19. Which keyword is used to prevent inheritance in Java?
A) static
B) final
C) abstract
D) const
20. Which collection class allows duplicate elements?
A) HashSet
B) TreeSet
C) ArrayList
D) EnumSet
21. Which exception is thrown when dividing by zero in Java?
A) IOException
B) ArithmeticException
C) NullPointerException
D) SQLException
22. What is the parent class of all classes in Java?
A) Main
B) System
C) Object
D) Class
23. Which interface is implemented by ArrayList?
A) Set
B) Map
C) Queue
D) List
24. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) do-while loop
D) enhanced for loop
25. Which package contains Scanner class?
A) [Link]
B) [Link]
C) [Link]
D) [Link]
26. What is the size of int data type in Java?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) Depends on system
27. Which access modifier allows access only within the same class?
A) public
B) protected
C) default
D) private
28. Which method is the entry point of a Java application?
A) start()
B) run()
C) main()
D) execute()
29. Which of the following is not a primitive data type in Java?
A) float
B) String
C) char
D) boolean
30. Which operator is used to compare object references in Java?
A) equals()
B) ==
C) !=
D) compareTo()