PRACTICE • LEARN • GROW
Module 6: Object-Oriented Programming — 4 Pillars - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 6: Object-Oriented Programming — 4 Pillars - Final Quiz Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
Which of the following correctly pairs the Four Pillars of OOP with their primary design purpose?
A.
Encapsulation (Data hiding), Inheritance (Code reuse), Polymorphism (Many forms), Abstraction (Hiding implementation complexity)
B.
Encapsulation (Fast compilation), Inheritance (Dynamic arrays), Polymorphism (Pointer arithmetic), Abstraction (Thread locks)
C.
Encapsulation (Memory garbage collection), Inheritance (Static methods), Polymorphism (Overloading only), Abstraction (Bytecode)
D.
Encapsulation (Multiple inheritance), Inheritance (Virtual tables), Polymorphism (Single thread), Abstraction (Private variables)
Explanation & Key
Correct Answer:
2
How is proper Encapsulation achieved in a Java class?
A.
By making all fields public so any class can inspect them directly
B.
By declaring instance fields as private and providing public getter and setter methods with validation
C.
By declaring all methods static
D.
By extending the Thread class
Explanation & Key
Correct Answer:
3
Which of the following is NOT required to build a 100% Immutable Class in Java?
A.
Declare the class as final so it cannot be subclassed
B.
Declare all fields as private and final
C.
Do not provide any setter methods
D.
Provide public setters that return a boolean indicating success
Explanation & Key
Correct Answer:
4
Why does Java disallow multiple inheritance with classes (e.g.,
class C extends A, B)?
A.
To avoid the Diamond Problem where ambiguity arises if both parent classes define conflicting implementations of the same method
B.
Because the JVM can only load one class at a time
C.
Because subclasses cannot have more fields than parent classes
D.
To force all developers to write single-threaded code
Explanation & Key
Correct Answer:
5
What is Dynamic Method Dispatch in Java?
A.
Compiling methods into machine code at startup
B.
The runtime resolution mechanism where an overridden method call on a parent reference is bound to the child object's method via a vtable lookup
C.
Calling a method over a network socket
D.
Overloading methods with different parameters
Explanation & Key
Correct Answer:
6
What happens when compiling this method overriding code?
class Parent {
void show() {}
}
class Child extends Parent {
int show() { return 10; }
}
A.
It compiles successfully and overloads show()
B.
Compile-time error: show() in Child cannot override show() in Parent because return type int is incompatible with void
C.
It compiles and returns 10 at runtime
D.
Runtime ClassCastException
Explanation & Key
Correct Answer:
7
Which annotation tells the Java compiler to verify that a method is genuinely overriding a method from its superclass or interface?
A.
@Polymorphic
B.
@Override
C.
@Super
D.
@Inherit
Explanation & Key
Correct Answer:
8
Which access modifier in Java allows access to subclasses even if they reside in different packages?
A.
private
B.
default (package-private)
C.
protected
D.
final
Explanation & Key
Correct Answer:
9
What will be the output of the following code demonstrating instance variable vs method polymorphism?
class Parent {
int x = 10;
void print() { System.out.print("P:" + x + " "); }
}
class Child extends Parent {
int x = 20;
void print() { System.out.print("C:" + x + " "); }
}
public class Test {
public static void main(String[] args) {
Parent obj = new Child();
System.out.print(obj.x + " ");
obj.print();
}
}
A.
20 C:20
B.
10 C:20
C.
10 P:10
D.
20 P:20
Explanation & Key
Correct Answer:
10
Does Java permit an overriding method in a subclass to return a more specific subtype than the return type declared in the superclass?
class Animal {}
class Dog extends Animal {}
class Shelter {
Animal adopt() { return new Animal(); }
}
class DogShelter extends Shelter {
@Override
Dog adopt() { return new Dog(); }
}
A.
No, overriding strictly requires the exact same return type
B.
Yes, Java supports covariant return types where the child method can return a subtype of the parent method's return type
C.
Only if both methods are declared static
D.
Only if the return type implements Serializable
Explanation & Key
Correct Answer:
11
What happens if a subclass attempts to override a method declared as
final in the superclass?
A.
The method is overridden normally
B.
Compile-time error: cannot override final method from superclass
C.
The child method executes only if invoked with super
D.
The final modifier is removed automatically
Explanation & Key
Correct Answer:
12
What happens if a class implements two interfaces that both define a default method with the exact same name and signature?
interface A { default void show() { System.out.println("A"); } }
interface B { default void show() { System.out.println("B"); } }
class C implements A, B {
}
A.
Interface A's method is picked because it was listed first
B.
Compile-time error: class C inherits unrelated defaults for show() from types A and B
C.
Both methods execute sequentially
D.
The code compiles and throws AbstractMethodError at runtime
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong