Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

MidtermExam-OOP-MakScie

Total questions: 93

Worksheet time: 2hrs 33mins

Name
Class
Date
1.

What is the main purpose of encapsulation in Python OOP?

a)

To increase execution speed

b)

To hide implementation details and protect data

c)

To allow multiple inheritance

d)

To avoid using classes

2.

In Python, how do you define a private variable inside a class?

a)

By prefixing with #

b)

By prefixing with _ (single underscore)

c)

By prefixing with __ (double underscore)

d)

By declaring it as private

3.

Which of the following demonstrates encapsulation properly?

a)

self.__name is accessible only inside the class

b)

self.__name can be modified directly

c)

self.__name is a class method

d)

Encapsulation is not applied here

4.

Which method is typically used to access a private variable?

a)

Global variable

b)

Getter method

c)

Direct assignment

d)

Operator overloading

5.

Which of the following is NOT an advantage of encapsulation?

a)

Data protection

b)

Code reusability

c)

Data hiding

d)

Preventing inheritance

6.

Which principle does encapsulation directly support?

a)

Polymorphism

b)

Abstraction

c)

Overloading

d)

Composition

7.

What is true about public variables in Python?

a)

Can only be accessed inside class

b)

Accessible anywhere

c)

Automatically private

d)

Not allowed in classes

8.

Which keyword is used in Python to enforce encapsulation strictly?

a)

private

b)

protected

c)

No strict keyword exists

d)

secure

9.

What happens if you try to access a private variable directly?

a)

Error

b)

Value is shown normally

c)

Python performs name mangling

d)

It becomes read-only

10.

Which of these is a good reason to use encapsulation?

a)

Faster loops

b)

Cleaner UI

c)

Prevent unauthorized access

d)

Debugging only

11.

Which is NOT part of encapsulation?

a)

Getters

b)

Setters

12.

Encapsulation allows:

a)

Multiple return values

b)

Secure modification of variables

c)

Faster compilation

d)

Dynamic typing

13.

What is the recommended way to modify a private variable?

a)

Access directly with object.__var

b)

Use a setter method

c)

Use reflection

d)

No way exists

14.

Which principle is violated if encapsulation is broken?

a)

DRY principle

b)

Information hiding

c)

Loosely coupled design

d)

Polymorphism

15.

In Python, which keyword is used to define inheritance?

a)

extends

b)

implements

c)

inherit

d)

class ParentClass

16.

What type of inheritance is this?

a)

Multiple inheritance

b)

Single inheritance

c)

Multilevel inheritance

d)

Hybrid inheritance

17.

If class C inherits from both A and B, what is this called?

a)

Multiple inheritance

b)

Single inheritance

c)

Hybrid inheritance

d)

Hierarchical inheritance

18.

Which Python feature helps to resolve diamond problem in inheritance?

a)

super()

b)

Polymorphism

c)

Decorators

d)

Abstract classes

19.

Which function checks if a class is a subclass of another?

a)

isinstance()

b)

issubclass()

c)

mro()

d)

id()

20.

Which type of inheritance is shown?

a)

Single

b)

Multilevel

c)

Multiple

d)

Hybrid

21.

Which inheritance type is a combination of two or more?

a)

Multilevel

b)

Multiple

c)

Hybrid

d)

Single

22.

Which keyword is used to call a parent class constructor?

a)

parent()

b)

base()

c)

super()

d)

root()

23.

What happens if both parent and child have the same method name?

a)

Error

b)

Child method overrides parent method

c)

Parent method overrides child method

d)

Both methods run together

24.

Which of the following supports method overriding?

a)

Encapsulation

b)

Inheritance

c)

Polymorphism

d)

Abstraction

25.

What does the super() function return?

a)

Parent class object

b)

Child class object

c)

Global object

d)

None

26.

Which inheritance structure is generally discouraged?

a)

Single

b)

Multiple with diamond shape

c)

Multilevel

d)

Hybrid

27.

Which operator is used for floor division in Python?

a)

/

b)

//

c)

%

d)

**

28.

What will be the output of: x, y = 5, 2 print(x ** y)

a)

2.5

b)

25

c)

7

d)

10

29.

Which operator is used for string repetition?

a)

*

b)

+

c)

,

d)

**

30.

Which operator checks identity in Python?

a)

==

b)

is

c)

!=

d)

in

31.

What will be output? x = [1,2,3] y = x print(x is y)

a)

False

b)

True

c)

Error

d)

None

32.

Which operator is overloaded by __add__() method?

a)

+

b)

-

c)

*

d)

/

33.

Which operator is used for membership testing?

a)

in

b)

is

c)

==

d)

!=

34.

Which operator gives remainder?

a)

/

b)

%

c)

//

d)

**

35.

Which operator is overloaded by __str__() method?

a)

print()

b)

String conversion

c)

Concatenation

d)

Multiplication

36.

Which of the following is NOT a Python control structure?

a)

if-else

b)

for loop

c)

switch-case

d)

while loop

37.

What is the output of: for i in range(2, 6, 2): print(i, end=" ")

a)

A. 2 3 4 5

b)

B. 2 4

c)

C. 2 6

d)

D. Error

38.

Which keyword is used to exit a loop immediately?

a)

continue

b)

break

c)

pass

d)

exit

39.

Which keyword is used to skip the current iteration in a loop?

a)

continue

b)

break

c)

skip

d)

pass

40.

What will be the output?

a)

The code will print '0 1 2'

b)

The code will print '0 0 0 ...'

c)

The code will result in an error

d)

The code will print nothing

41.

x += 1

a)

0 1

b)

0 1 2

c)

1 2 3

d)

Infinite loop

42.

Which of the following is valid Python code?

a)

for(i=0;j<5;i++)

b)

for i in range(5):

c)

loop i=0 to 5

d)

foreach i in range(5)

43.

Which loop runs at least once in Python?

a)

while

b)

do-while

c)

for

d)

None

44.

What is the purpose of the else in a loop?

a)

Runs if loop breaks

b)

Runs if loop completes normally without break

c)

Runs before loop starts

d)

Cannot be used in Python

45.

What will this code print? for i in range(3): pass print("Done")

a)

Done

b)

0 1 2 Done

c)

Nothing

d)

Error

46.

Which keyword is used for an empty block?

a)

empty

b)

none

c)

pass

d)

skip

47.

Which loop is more suitable for iterating through lists?

a)

for

b)

while

c)

do-while

d)

switch

48.

Which statement stops execution of the current function?

a)

break

b)

continue

c)

return

d)

pass

49.

Which construct can replace multiple if-elif chains more efficiently?

a)

while

b)

dictionary mapping

c)

pass

d)

recursion

50.

Which loop is used when the number of iterations is unknown?

a)

for

b)

while

c)

foreach

d)

switch

51.

Which of the following is public in Python by default?

a)

Variables without underscore

b)

Variables with one underscore

52.

What does a single underscore (_var) indicate?

a)

Strong private

b)

Weak private (internal use)

c)

Protected and cannot be accessed

d)

Global variable

53.

Which is stronger in Python?

a)

_var

b)

__var

c)

Both are same

d)

None

54.

Which variable type can still be accessed with name mangling?

a)

Public

b)

Protected

c)

Private (__var)

d)

Constant

55.

What is the best practice to access protected members?

a)

Directly outside class

b)

Through child classes

c)

Using global variable

d)

Not possible

56.

What happens if you declare a variable as _x?

a)

Cannot be accessed outside

b)

Still accessible but discouraged

c)

Becomes private

d)

Raises error

57.

Which member has the highest restriction?

a)

Public

b)

Protected

c)

Private

58.

Which of these is a valid Python convention?

a)

varPublic → public

b)

_var → protected

c)

__var → private

d)

All of the above

59.

Which variables are accessible everywhere?

a)

Private

b)

Protected

c)

Public

d)

Encapsulated

60.

Access modifiers in Python are enforced by:

a)

Compiler

b)

Interpreter rules

c)

Naming convention and name mangling

d)

Operating system

61.

Which Python decorator is used for getters?

a)

@staticmethod

b)

@getter

c)

@property

d)

@classmethod

62.

How do you define a setter in Python?

a)

@setter directly

b)

@.setter

c)

Assigning variable directly

d)

Using global keyword

63.

self.__x = 10 @property def x(self): return self.__x a = A() print(a.x)

a)

10

b)

Error

c)

None

d)

__x

64.

Which of these allows attribute validation before setting?

a)

Getter

b)

Setter

c)

Constructor

d)

Destructor

65.

What is true about getters and setters?

a)

They replace encapsulation

b)

They implement encapsulation

c)

They remove need for private variables

d)

They prevent constructors

66.

Which decorator is used to delete a property?

a)

@deleter

b)

@property.deleter

c)

@del

d)

@remove

67.

Given the following code: self.__age = 20 @property def age(self): return self.__age @age.setter def age(self, value): if value > 0: self.__age = value a = A() a.age = 25 print(a.age)

a)

A. 20

b)

B. 25

c)

C. Error

d)

D. None

68.

Which of these is an advantage of @property?

a)

Simpler syntax than getter methods

b)

Faster execution

c)

Supports operator overloading

d)

Avoids constructors

69.

Which function allows checking if an attribute exists?

a)

hasattr()

b)

getattr()

c)

setattr()

d)

delattr()

70.

Which diagram is used to represent class relationships in OOP?

a)

Sequence diagram

b)

Flowchart

c)

Class diagram

d)

State diagram

71.

In UML, a filled diamond represents:

a)

Association

b)

Aggregation

c)

Composition

d)

Inheritance

72.

Which symbol shows inheritance in a class diagram?

a)

Solid arrow with closed head

b)

Dotted arrow

c)

Open arrow

d)

Triangle arrow

73.

Which of these represents "uses-a" relationship?

a)

Association

b)

Aggregation

c)

Composition

d)

Generalization

74.

Which of these represents "is-a" relationship?

a)

Aggregation

b)

Inheritance

c)

Composition

d)

Dependency

75.

Which method is the constructor in Python?

a)

__init__()

b)

__main__()

76.

What is the output?

a)

No output

b)

Error

c)

Constructor called

d)

None

77.

How many constructors can a Python class have?

a)

Only one __init__ method

b)

Multiple with different signatures

c)

None

d)

Unlimited

78.

What is a default constructor?

a)

Constructor with no parameters

b)

Constructor with parameters

c)

Abstract constructor

d)

Constructor from parent class

79.

What happens if a class has no constructor?

a)

Error

b)

Python creates a default one

c)

No object can be created

d)

Destructor is used

80.

Which keyword is used inside constructor to refer to object?

a)

this

b)

self

c)

object

81.

What will be the output?

a)

0 20

b)

10 20

c)

None 20

d)

Error

82.

What will happen if parent and child both have constructors?

a)

Both run automatically

b)

Only parent runs

c)

Only child runs unless super() is used

d)

Error

83.

Which of the following is used for multiple ways of constructing objects?

a)

Constructor chaining

b)

Overloading

c)

Default constructor

d)

Encapsulation

84.

Which method is called before __init__()?

a)

__new__()

b)

__start__()

c)

__create__()

d)

__build__()

85.

Does Python support traditional method overloading?

a)

Yes, fully

b)

No, only latest defined method is used

c)

Yes, using @overload decorator only

d)

Yes, with multiple constructors

86.

What is the output?

a)

Error

b)

Hello Alice

c)

Hello Hello Alice

d)

None

87.

Which of these allows pseudo-overloading?

a)

Method overriding

b)

Default arguments

c)

Decorators only

d)

Abstract methods

88.

Which operator is overloaded by __eq__()?

a)

==

b)

=

c)

!=

89.

Which operator is overloaded by __lt__()?

a)

<=

b)

<

c)

>

d)

>=

90.

Which operator is overloaded by __mul__()?

a)

*

b)

**

c)

//

d)

%

91.

Which method is called when str(obj) is executed?

a)

__repr__()

b)

__str__()

c)

__doc__()

d)

__name__()

92.

Which method is called when len(obj) is executed?

a)

__count__()

b)

__size__()

c)

__len__()

d)

__iter__()

93.

Which method is called for obj1 + obj2?

a)

__sum__()

b)

__add__()

c)

__plus__()

d)

__concat__()