Java OOPs MCQs (Multiple Choice Questions)

11.) What is a constructor in Java?

A) A method that is inherited from the superclass
B) A method used to destroy objects
C) A special method used to initialize objects
D) A method used to override superclass methods

Answer: Option C

Explanation: A constructor is a special method that is automatically called when an object of a class is created, and it is used to initialize the object’s attributes.

12.) Which OOP concept allows a class to provide a clear and consistent public interface while hiding its internal implementation?

A) Inheritance
B) Polymorphism
C) Encapsulation
D) Abstraction

Answer: Option C

Explanation: Encapsulation involves bundling data and methods into a single unit (class) and controlling access to the data through public methods, allowing the internal details to be hidden.

13.) Which keyword is used to indicate that a class cannot be inherited by any other class?

A) final
B) abstract
C) static
D) sealed

Answer: Option A

Explanation: The “final” keyword is used to indicate that a class, method, or variable cannot be further extended, overridden, or modified.

14.) What is the purpose of an interface in Java?

A) To create a new instance of a class
B) To define a blueprint for a class
C) To encapsulate data and behavior
D) To provide default implementations for methods

Answer: Option B

Explanation: An interface defines a set of methods that a class must implement, serving as a contract that specifies what methods a class should provide.

15.) Which access modifier allows a class’s members to be accessible within the same package and by subclasses in different packages?

A) private
B) protected
C) public
D) default (package-private)

Answer: Option B

Explanation: The “protected” access modifier allows class members to be accessible within the same package and by subclasses, regardless of whether they are in the same or different packages.

16.) What is the term used to describe the ability of an object to take on many forms through inheritance and interface implementation?

A) Encapsulation
B) Abstraction
C) Polymorphism
D) Inheritance

Answer: Option C

Explanation: Polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling different implementations to be used interchangeably.

17.) Which OOP concept allows a class to inherit properties and behaviors from multiple superclasses?

A) Encapsulation
B) Polymorphism
C) Multiple inheritance
D) Method overloading

Answer: Option C

Explanation: Multiple inheritance allows a class to inherit attributes and methods from more than one superclass. Java supports multiple interface inheritance, but not multiple class inheritance.

18.) What is the purpose of method overriding in Java?

A) To create new methods in a subclass
B) To hide the superclass methods
C) To provide a new implementation for a superclass method in a subclass
D) To prevent subclasses from accessing superclass methods

Answer: Option C

Explanation: Method overriding allows a subclass to provide its own implementation for a method that is already defined in its superclass, enabling polymorphic behavior.

19.) Which OOP concept allows you to create a new class that includes the attributes and methods of an existing class and introduces new properties?

A) Inheritance
B) Encapsulation
C) Abstraction
D) Polymorphism

Answer: Option A

Explanation: Inheritance allows you to create a new class (subclass) based on an existing class (superclass), inheriting its attributes and methods while adding or modifying behavior.

20.) What is the term used to describe the process of hiding the implementation details of an object and only exposing necessary features?

A) Abstraction
B) Inheritance
C) Polymorphism
D) Encapsulation

Answer: Option D

Explanation: Encapsulation involves hiding the internal details of an object and exposing a controlled interface to interact with the object, promoting modularity and code organization.

See All Java Programming MCQs: All Java Programming MCQs