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!

Q1

Q1 Which principle of OOP allows for the same function to be used in different ways?

A

Inheritance

B

Polymorphism

C

Encapsulation

D

Abstraction

Q2

Q2 What does OOP stand for?

A

Object-Oriented Programming

B

Objective Operation Procedure

C

Oriented Object Programming

D

Operational Object Programming

Q3

Q3 Which of the following is NOT a basic concept of OOP?

A

Classes

B

Objects

C

Functions

D

Inheritance

Q4

Q4 OOP aims to make software development more:

A

Error-prone

B

Flexible

C

Complicated

D

Sequential

Q5

Q5 Which concept of OOP encapsulates the properties (data) and behaviors (methods) of a real-world object into a single entity?

A

Polymorphism

B

Encapsulation

C

Inheritance

D

Abstraction

Q6

Q6 The concept of hiding the internal implementation details of a class and showing only its functionality is known as:

A

Encapsulation

B

Abstraction

C

Polymorphism

D

Inheritance

Q7

Q7 In OOP, an "object" is:

A

An instance of a class

B

A type of data structure

C

A programming technique

D

A method definition

Q8

Q8 What is the output of the following Python code?
class Animal:
def speak(self):
return "makes a sound"
class Dog(Animal):
def speak(self):
return "barks"
print(Dog().speak())

A

makes a sound

B

barks

C

SyntaxError

D

None

Q9

Q9 Which keyword is used to create a class in Java?

A

class

B

Class

C

object

D

Object

Q10

Q10 A programmer defines a class but fails to create an instance of that class. They try to call a method of the class directly.
What type of error will occur?

A

Compilation error

B

Runtime error

C

Logical error

D

No error

Q11

Q11 If a class Car has a method drive() that requires no arguments, which of the following calls is correct after creating a Car object named myCar?

A

Car.drive()

B

myCar.drive()

C

drive(myCar)

D

Car().drive()

Q12

Q12 What is an object in programming?

A

A piece of data

B

A runtime entity

C

A template for creating objects

D

A function

Q13

Q13 In the context of OOP, what does a class provide?

A

A blueprint for objects

B

A specific data type

C

A method implementation

D

A programming pattern

Q14

Q14 Which of the following is a characteristic of an object?

A

Encapsulation

B

Inheritance

C

Polymorphism

D

Identity

Q15

Q15 The process of creating an object from a class is known as:

A

Encapsulation

B

Instantiation

C

Inheritance

D

Abstraction

Q16

Q16 Which of the following best describes the concept of "state" in an object?

A

The behavior the object exhibits

B

The methods the object can execute

C

The data stored within the object

D

The class from which the object is derived

Q17

Q17 Which term best describes an instance variable of a class?

A

A variable defined within a method

B

A variable accessible by all instances of a class and shared across them

C

A variable unique to each instance of a class

D

A constant value that cannot be changed

Q18

Q18 What is the main difference between a class and an object?

A

A class is a blueprint, while an object is an instance of a class

B

A class is executable code, while an object is not

C

A class cannot exist without objects, while an object can exist without classes

D

A class is used only in object-oriented programming, while objects can be used in any programming paradigm

Q19

Q19 How do objects in OOP communicate with each other?

A

Through global functions

B

By calling methods on each other

C

Using special OOP communication operators

D

By accessing each other's memory directly

Q20

Q20 Which keyword is used in Java to create a new object?

A

new

B

class

C

object

D

this

Q21

Q21 Given the following Java code, what is the output?
class Box {
int width;
Box(int w) {
width = w;
}
}
public class Test {
public static void main(String[] args) {
Box myBox = new Box(5);
System.out.println(myBox.width);
}
}

A

5

B

0

C

Error

D

None

Q22

Q22 What is the result of compiling and running the following code in Java?
class Counter {
private int count = 0;
void increment() {
count++;
}
int getCount() {
return count;
}
}

A

Compilation error

B

Runtime error

C

0

D

None of the above

Q23

Q23 Which of the following is the correct way to define a constructor in Java?

A

public void ClassName() {}

B

ClassName() {}

C

public ClassName() {}

D

constructor ClassName() {}

Q24

Q24 Considering the principle of encapsulation, which option correctly makes age a private attribute and provides public getter and setter methods in a Java class?

A

private int age; public int getAge() { return age; } public void setAge(int a) { age = a; }

B

int age; public int readAge() { return age; } public void writeAge(int a) { age = a; }

C

private int age; public int age() { return age; } public void age(int a) { age = a; }

D

int age; public int getAge() { return age; } public void age(int a) { age = a; }

Q25

Q25 Identify the mistake in the following Java code snippet:
class Student {
private int score;
public static void setScore(int s) {
score = s;
}
}

A

score should not be private

B

s is not correctly passed to score

C

setScore cannot be static as it accesses an instance variable

D

None of the above

Q26

Q26 A programmer attempts to compile the following Java code but encounters an error:
class MyClass { void MyClass() { } }.
What is the mistake?

A

The constructor has a return type

B

The class name is incorrect

C

The constructor is defined as a method

D

None of the above

Q27

Q27 In the context of Java, what does the following error indicate?
java.lang.NullPointerException

A

An attempt to access a class file that does not exist

B

An attempt to use a reference that points to no location in memory

C

Incorrect syntax

D

None of the above

Q28

Q28 After adding a new feature to a class, a programmer notices that creating an object of that class now throws an error.
What is the MOST likely cause?

A

The class does not have a constructor

B

The new feature conflicts with existing methods

C

There is a syntax error in the new feature

D

The class was not compiled after adding the new feature

Q29

Q29 Which keyword is used in Java to inherit a class?

A

extends

B

implements

C

inherits

D

super

Q30

Q30 Polymorphism in OOP allows for:

A

objects to take on multiple forms

B

methods to execute concurrently

C

classes to encapsulate data and methods

D

objects to be instantiated without classes

ad verticalad vertical
ad