oops banner

OOPs Multiple Choice Questions (MCQs) and Answers

Master Object-Oriented Programming (OOPs) with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of OOPs concepts in Java. Begin your placement preparation journey now!

Q31

Q31 In the context of OOP, what is "method overriding"?

A

Defining a method in a subclass that already exists in the parent class with a different implementation

B

Increasing the visibility of a method in a subclass

C

Changing the return type of a method in a subclass

D

None of the above

Q32

Q32 What does the super keyword in Java do?

A

It is used to call superclass methods

B

It defines a superclass

C

It overrides a method in the superclass

D

It creates an instance of a superclass

Q33

Q33 Which of the following best describes "dynamic polymorphism"?

A

Compile-time method binding

B

The ability to create dynamic classes at runtime

C

Method overriding where method calls are resolved at runtime

D

The creation of objects at runtime

Q34

Q34 What is an "abstract class" in Java?

A

A class that cannot be instantiated and must be inherited

B

A class that can only contain abstract methods

C

A class without any implementation

D

A final class that cannot be extended

Q35

Q35 To achieve polymorphism in Java, one must use:

A

Interfaces only

B

Abstract classes only

C

Either interfaces or abstract classes

D

Direct class inheritance only

Q36

Q36 Which concept describes the ability of different classes to respond to the same method call in their own unique ways?

A

Encapsulation

B

Inheritance

C

Polymorphism

D

Composition

Q37

Q37 When does the "diamond problem" occur in programming?

A

When multiple interfaces are implemented

B

When a class inherits from two classes with the same method

C

When multiple classes inherit from a single class

D

None of the above

Q38

Q38 Which feature distinguishes interfaces from abstract classes in Java?

A

Interfaces cannot have any method implementations

B

Interfaces can have only final static fields

C

Abstract classes can contain non-final methods

D

Interfaces support multiple inheritance

Q39

Q39 What is the output of the following code snippet in Java?
class Animal {
public void sound() {
System.out.println("Animal sound");
}
}
class Dog extends Animal {
public void sound() {
System.out.println("Bark");
}
}
public class Test {
public static void main(String[] args) {
Animal myAnimal = new Dog();
myAnimal.sound();
}
}

A

"Animal sound"

B

"Bark"

C

Compilation error

D

None of the above

Q40

Q40 Given the following Java code, which principle is demonstrated?
interface Flyable {
void fly();
}
class Bird implements Flyable {
public void fly() {
System.out.println("Bird flies");
}
}
class Airplane implements Flyable {
public void fly() {
System.out.println("Airplane flies");
}
}

A

Inheritance

B

Encapsulation

C

Polymorphism

D

Abstraction

Q41

Q41 In Java, which method signature indicates that a method is overriding a method from its superclass?

A

A method with the same name but a different return type

B

A method with the same name and parameter list as in the superclass

C

A static method with the same name as in the superclass

D

A method with the same name but different parameter types

Q42

Q42 What will happen if a subclass in Java tries to override a superclass method marked as final?

A

The subclass method will successfully override the superclass method

B

The compiler will generate an error

C

The superclass method will be hidden

D

None of the above

Q43

Q43 Given two classes, Base and Derived, where Derived extends Base and both classes have a method show() with different implementations.
How is polymorphic behavior achieved when calling show() on a Derived object referenced by a Base type?

A

By marking show() in Base as final

B

By using the static keyword in Derived's show() method

C

By overriding show() in Derived

D

None of the above

Q44

Q44 A programmer cannot access a superclass method from a subclass in Java.
What is the most likely reason?

A

The subclass does not extend the superclass

B

The method in the superclass is marked as private

C

The method in the superclass is static

D

None of the above

Q45

Q45 After refactoring a class hierarchy, a method call on a subclass object executes the superclass method instead of the overridden method.
What is the likely cause?

A

The overridden method in the subclass is marked as private

B

The method call is statically bound

C

The subclass method does not correctly override the superclass method due to a signature mismatch

D

None of the above

Q46

Q46 A Java program throws a ClassCastException when casting an object of a superclass to a subclass.
What is the most probable reason?

A

The object actually belongs to another unrelated class

B

The object is of the superclass type and cannot be cast down without an explicit check

C

The subclass is abstract

D

None of the above

Q47

Q47 In a Java application utilizing interfaces, a new class implements an interface but fails to provide implementations for all declared methods.
What error will this cause?

A

NullPointerException

B

InstantiationException

C

CompilationError

D

ClassCastException

Q48

Q48 Which of the following best describes encapsulation?

A

Combining data and methods into a single unit

B

Breaking down a complex problem into smaller parts

C

Allowing an object to perform many forms of behavior

D

Hiding the internal state of an object from the outside world

Q49

Q49 What is the primary purpose of abstraction in OOP?

A

To speed up the execution of programs

B

To reduce code complexity and increase reusability

C

To hide the internal implementation details and only show the features to the users

D

To ensure secure data manipulation without external interference

Q50

Q50 Which keyword in Java is used to hide a class member from classes in other packages?

A

private

B

protected

C

public

D

transient

Q51

Q51 In OOP, abstract methods are:

A

Methods that are fully implemented

B

Methods that are declared but not implemented

C

Methods that cannot be overridden

D

Methods that must be static

Q52

Q52 What does it mean when a class is declared as abstract?

A

The class cannot be instantiated directly and must be subclassed

B

The class does not contain any methods

C

The class is a final class and cannot have any subclasses

D

The class can only contain static methods

Q53

Q53 How can encapsulation be achieved in a class?

A

By declaring all variables as static

B

By declaring all class methods as final

C

By making member variables private and providing public getter and setter methods

D

By using abstract classes only

Q54

Q54 The process of minimizing the exposure of details from one part of a program to another is known as:

A

Encapsulation

B

Abstraction

C

Polymorphism

D

Inheritance

Q55

Q55 What is the difference between encapsulation and abstraction?

A

Encapsulation is about hiding the details, abstraction is about showing only essential features

B

Encapsulation is a design guideline, whereas abstraction is a programming concept

C

Encapsulation deals with data, and abstraction deals with classes

D

There is no significant difference

Q56

Q56 Which OOP feature provides a way to protect objects from unintended direct field access?

A

Inheritance

B

Polymorphism

C

Encapsulation

D

Abstraction

Q57

Q57 What will be the output of the following Java code snippet?
class Encapsulate {
private int num = 10;
public int getNum() {
return num;
}
} public class Test {
public static void main(String[] args) {
Encapsulate obj = new Encapsulate();
System.out.println(obj.getNum());
}
}

A

10

B

0

C

Compilation error

D

Runtime error

Q58

Q58 Given the following code, identify the abstraction technique used:
abstract class Shape {
abstract void draw();
}
class Rectangle extends Shape {
void draw() {
System.out.println("drawing rectangle");
}
}

A

Inheritance

B

Encapsulation

C

Polymorphism

D

Abstraction

Q59

Q59 Which of the following changes will make the code below correctly encapsulate the age property?
class Person {
int age; public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

A

Change int age; to private int age;

B

Add static keyword to age

C

Remove the setter method

D

Change public methods to private

Q60

Q60 How can you ensure that a class adheres to the abstraction principle by not allowing instantiation but permitting subclassing?

A

Declare the class as final

B

Declare the class as static

C

Declare the class with private constructors

D

Declare the class as abstract

ad verticalad vertical
ad