wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

OOP Concepts Quiz

Total questions: 81

Worksheet time: 41mins

Name
Class
Date
1.

The main purpose of Object-Oriented Programming is to ___.

a)

Increase code length

b)

Use functions only

c)

Model real-world entities in code

d)

Avoid variables

2.

Which feature best distinguishes OOP from procedural programming?

a)

Functions

b)

Control structures

c)

Encapsulation of data and behavior

d)

Conditional statements

3.

In OOP, data and functions that operate on that data are bundled together inside a ___.

a)

Method

b)

Function

c)

Class

d)

Module

4.

The concept of reusing code through inheritance represents which OOP advantage?

a)

Abstraction

b)

Modularity

c)

Code reusability

d)

Polymorphism

5.

OOP helps achieve which of the following goals in software design?

a)

Tight coupling

b)

Code duplication

c)

Maintainability and reusability

d)

Complex dependency

6.

Which of the following is not a benefit of OOP?

a)

Easier maintenance

b)

Code reuse

c)

High security via data hiding

d)

Increased code redundancy

7.

OOP allows programmers to create __ objects from the same class without rewriting code.

a)

Infinite

b)

Static

c)

Local

d)

Global

8.

What is the main difference between OOP and procedural programming?

a)

OOP focuses on data and objects; procedural focuses on functions

b)

Procedural programming uses classes

c)

OOP has no loops

d)

Both are identical in structure

9.

In Python, Object-Oriented Programming is implemented through ___.

a)

Classes and objects

b)

Functions only

c)

Libraries only

d)

Modules only

10.

Program Example: class A: def __init__(self): self.x = 5 obj = A() print(obj.x) What will this code print?

a)

Error

b)

Nothing

c)

5

d)

x

11.

What is a class in Python?

a)

A collection of functions

b)

A blueprint for creating objects

c)

A data-type like list or tuple

d)

A loop control structure

12.

Which keyword is used to define a class in Python?

a)

def

b)

object

c)

class

d)

method

13.

In Python, the first argument of every class method must be ___.

a)

cls

b)

self

c)

this

d)

obj

14.

When a class is defined, what is actually created in memory?

a)

A function object

b)

A class object (template)

c)

An instance

d)

A variable

15.

A class can contain:

a)

Only variables

b)

Only functions

c)

Both data and functions

d)

Only data types

16.

Program Output: class Car: wheels = 4 print(Car.wheels) What will be the output?

a)

Error

b)

4

c)

wheels

d)

None

17.

Which of the following creates an object of a class named “Student”?

a)

obj = Student[]

b)

obj = Student()

c)

obj = new Student

d)

obj = Student.create()

18.

A variable defined inside a class but outside any method is called ___.

a)

Instance variable

b)

Global variable

c)

Class variable

d)

Local variable

19.

Program Output: class A: x = 10 def show(self): print(self.x + 5) obj = A() obj.show() What will this print?

a)

5

b)

10

c)

15

d)

Error

20.

Which statement is true about class definition?

a)

You must always include an __init__ method.

b)

A class can exist without any methods.

c)

A class cannot have multiple methods.

d)

A class must return something.

21.

What is an object in Python OOP?

a)

A loop control variable

b)

An instance of a class

c)

A file handle

d)

A function argument

22.

Every object in Python has its own ___.

a)

Constructor

b)

Unique identity, type, and value

c)

Function name

d)

Local scope only

23.

Program Output: class Dog: def __init__(self, name): self.name = name d1 = Dog("Max") print(d1.name) A) Error B) Dog C) Max D) None

a)

Error

b)

Dog

c)

Max

d)

None

24.

Which statement creates two separate objects of the same class?

a)

a = b = MyClass()

b)

a = MyClass(); b = MyClass()

c)

a, b = MyClass()

d)

a = copy(MyClass)

25.

In Python, object attributes can be accessed using the __ operator.

a)

::

b)

.

c)

->

d)

:

26.

What happens when an object is deleted in Python?

a)

__init__() runs again

b)

__del__() method is called if defined

c)

All class variables are reset

d)

Nothing happens

27.

Program Output: class A: def __init__(self, v): self.v = v x = A(10) y = x y.v = 20 print(x.v) A) 10 B) 20 C) Error D) None

a)

10

b)

20

c)

Error

d)

None

28.

Two objects with the same data but different memory locations are ___.

a)

Identical

b)

Equal but not identical

c)

Same reference

d)

None of these

29.

Which function returns the memory address of an object in Python?

a)

address()

b)

mem()

c)

id()

d)

loc()

30.

Program Output: class Student: def __init__(self, id): self.id = id def display(self): print("ID:", self.id) s = Student(101) s.display() A) ID 101 B) ID: 101 C) 101 D) Error

a)

ID 101

b)

ID: 101

c)

101

d)

Error

31.

What is a method in OOP?

a)

A variable declared inside a class

b)

A function defined inside a class

c)

A function outside a class

d)

A constructor

32.

The key difference between a function and a method is that a method ___.

a)

cannot return values

b)

is independent of any object

c)

is associated with a class or object

d)

runs without parentheses

33.

Which keyword is used to define a function or method in Python?

a)

function

b)

def

c)

define

d)

func

34.

In a class, which argument allows a method to access instance variables?

a)

this

b)

cls

c)

self

d)

obj

35.

Program Output: class Calc: def add(self, a, b): return a + b c = Calc() print(c.add(3, 5)) A) 8 B) 35 C) Error D) None

a)

8

b)

35

c)

Error

d)

None

36.

A method that operates on the class itself, not on any instance, is called ___.

a)

static method

b)

class method

c)

instance method

d)

public method

37.

Program Output: class A: @staticmethod def show(): return "Static" print(A.show()) A) Static B) Error C) None D) show

a)

Static

b)

Error

c)

None

d)

show

38.

What decorator is used for static methods?

a)

@method

b)

@static

c)

@staticmethod

d)

@function

39.

When a function is defined outside any class, it is called ___.

a)

method

b)

module

c)

function

d)

procedure

40.

Program Output: def greet(name): return "Hello " + name print(greet("User")) A) HelloUser B) Hello User C) Error D) name

a)

HelloUser

b)

Hello User

c)

Error

d)

name

41.

What is the purpose of __init__() in Python classes?

a)

To define class variables

b)

To initialize object attributes automatically when an object is created

c)

To delete objects

d)

To define static methods

42.

When is __init__() executed?

a)

When the class is defined

b)

Only when manually called

c)

Right after an object is created

d)

Before class definition

43.

Program Output: class A: def __init__(self): print("Init called") a = A() A) Nothing B) Error C) Init called D) Class A

a)

Nothing

b)

Error

c)

Init called

d)

Class A

44.

What is the output of the following code: class A: def __init__(self): print("Init called") a = A()

a)

Nothing

b)

Error

c)

Init called

d)

Class A

45.

What is the first argument of __init__() commonly called?

a)

this

b)

obj

c)

cls

d)

self

46.

Program Output: class Student: def __init__(self, name): self.name = name s1 = Student("Atif") print(s1.name)

a)

Atif

b)

name

c)

Error

d)

None

47.

If __init__() is missing from a class, Python ___.

a)

Throws an error

b)

Uses a default constructor automatically

c)

Stops execution

d)

Needs manual call

48.

How many __init__() methods can exist in a single Python class?

a)

Only one

b)

Two

c)

Unlimited

d)

Depends on inheritance

49.

Program Output: class A: def __init__(self, x=10): self.x = x a = A(20) print(a.x)

a)

10

b)

20

c)

None

d)

Error

50.

If you define __init__() with parameters but call the class without arguments, what happens?

a)

It prints None

b)

It uses default values

c)

It raises a TypeError

d)

It executes successfully

51.

Program Output: class Car: def __init__(self, model, year): self.model = model self.year = year c = Car("Civic", 2022) print(c.model, c.year)

a)

Civic 2022

b)

model year

c)

Error

d)

Civic Error

52.

A constructor in Python is a special method that ___.

a)

Deletes an object

b)

Initializes object data when it is created

c)

Runs only once at program end

d)

Is called manually by the user

53.

Which of the following acts as a constructor in Python?

a)

__main__()

b)

__start__()

c)

__init__()

d)

__object()

54.

Program Output: class Student: def __init__(self, name): print("Hello", name) s1 = Student("Atif")

a)

Hello Atif

b)

Error

c)

name

d)

None

55.

Which statement is true about constructors in Python?

a)

They can return values

b)

They are optional in a class

c)

They must always take arguments

d)

They can be defined only once per program

56.

What happens if a class has no __init__() method?

a)

Python throws an error

b)

A default constructor is automatically created

c)

The class cannot be instantiated

d)

Nothing happens

57.

Program Output: class A: def __init__(self, x=5): self.x = x obj = A() print(obj.x)

a)

Error

b)

None

c)

5

d)

x

58.

In Python, how do constructors differ from normal methods?

a)

They can be called many times

b)

They run automatically when the object is created

c)

They cannot access instance variables

d)

They don’t take self as a parameter

59.

Which constructor runs first in a derived class?

a)

Parent class constructor

b)

Child class constructor

c)

Both at the same time

d)

None

60.

Program Output: class Base: def __init__(self): print("Base") class Derived(Base): def __init__(self): super().__init__() print("Derived") obj = Derived()

a)

Derived Base

b)

Base Derived

c)

Error

d)

None

61.

Which method destroys an object when it’s no longer needed?

a)

__delete__()

b)

__remove__()

c)

__del__()

d)

__exit__()

62.

Which of the following best describes the main goal of OOP principles?

a)

To write the longest possible code

b)

To organize code around data and behavior

c)

To remove classes entirely

d)

To avoid modularity

63.

Which of these is not one of the four main principles of OOP?

a)

Inheritance

b)

Abstraction

c)

Compilation

d)

Polymorphism

64.

The OOP principle that hides internal details and shows only necessary features is called ___.

a)

Inheritance

b)

Abstraction

c)

Encapsulation

d)

Polymorphism

65.

The OOP principle that allows objects to take on many forms is known as ___.

a)

Encapsulation

b)

Polymorphism

c)

Inheritance

d)

Abstraction

66.

Which principle allows a subclass to use methods and attributes of a parent class?

a)

Overloading

b)

Overriding

c)

Inheritance

d)

Polymorphism

67.

Encapsulation primarily helps in ___.

a)

Data hiding and protection

b)

Increasing complexity

c)

Global variable sharing

d)

Making all variables public

68.

Program Output: class A: def __init__(self): self.__x = 10 def get_x(self): return self.__x obj = A() print(obj.get_x())

a)

Error

b)

10

c)

__x

d)

None

69.

Which OOP principle is most closely related to code reusability?

a)

Polymorphism

b)

Encapsulation

c)

Inheritance

d)

Abstraction

70.

Program Output: class Parent: def show(self): print("Parent") class Child(Parent): def show(self): print("Child") obj = Child() obj.show()

a)

Parent

b)

Child

c)

Error

d)

Both

71.

Which of the following principles helps achieve flexibility by allowing one interface to be used for different data types?

a)

Polymorphism

b)

Abstraction

c)

Inheritance

d)

Composition

72.

Which of the following are the four main pillars of Object-Oriented Programming?

a)

Loops, Conditions, Classes, Objects

b)

Encapsulation, Abstraction, Inheritance, Polymorphism

c)

Data Types, Variables, Methods, Functions

d)

None of these

73.

Which pillar focuses on hiding data within a class to prevent direct access from outside?

a)

Abstraction

b)

Encapsulation

c)

Inheritance

d)

Polymorphism

74.

Which pillar allows a subclass to reuse the methods and properties of a parent class?

a)

Abstraction

b)

Encapsulation

c)

Inheritance

d)

Polymorphism

75.

Program Output: class Parent: def show(self): print("Parent") class Child(Parent): def show(self): print("Child") c = Child() c.show()

a)

Parent

b)

Child

c)

Error

d)

None

76.

Which pillar is demonstrated when two methods in different classes share the same name but behave differently?

a)

Encapsulation

b)

Inheritance

c)

Abstraction

d)

Polymorphism

77.

Abstraction helps in ___.

a)

Hiding complex details and showing only essential features

b)

Showing all internal data

c)

Making data global

d)

Breaking security

78.

Program Output: from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass class Circle(Shape): def area(self): return 3.14 * 5 * 5 c = Circle() print(c.area())

a)

Error

b)

78.5

c)

25

d)

None

79.

Which of the following shows both Inheritance and Polymorphism?

a)

Using super().init() in child class

b)

Overriding a method from the parent class

c)

Declaring a private variable

d)

Creating abstract methods

80.

Program Output: class A: def display(self): print("A") class B(A): pass b = B() b.display()

a)

Error

b)

A

c)

B

d)

None

81.

Which pillar primarily enhances security and prevents unauthorized access to class data?

a)

Abstraction

b)

Encapsulation

c)

Inheritance

d)

Polymorphism