Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

OOPS Part 2 Quizs

Total questions: 18

Worksheet time: 9mins

Name
Class
Date
1.

True or False: The following line of code will delete the object my_student from memory.
del my_student

(a)  

2.

In Python, you can use the keyword private to hide an attribute from outside access. Is this statement true or false?

class MyClass:
    private_var = 10

a)

True

b)

False

3.

Encapsulation in programming means keeping an object's data private so that it can't be changed directly from outside the object. Is this true or false?

a)

True

b)

False

4.

True or False: In Python, if you create a class B that inherits from class A, and class A has a variable x = 1, then creating an object of B and printing b.x will output 1.

Test it online:
class A: x = 1 class B(A): pass b = B() print(b.x)

(a)  

5.

True or False: In the following code, the output will be B because the who method in class B overrides the one in class A.

class A: def who(self): print("A") class B(A): def who(self): print("B") b = B() b.who()

(a)  

6.

In Python, which symbol is commonly used to indicate that an attribute is intended to be private?

a)

_ (single underscore)

b)

$ (dollar sign)

c)

# (hash)

d)

@ (at symbol)

7.

Which of the following is NOT a feature of object-oriented programming?

a)

Encapsulation

b)

Inheritance

c)

Compilation

d)

Polymorphism

8.

In programming, does method overriding mean that a child class creates a method with the same name as the parent class, but with different code?

a)

TRUE

b)

FALSE

9.

Which keyword is used in Python to refer to the parent class when calling its methods from a child class?

a)

super()

b)

parent()

c)

base()

d)

main()

10.

In object-oriented programming, what is the main purpose of polymorphism?

a)

To allow objects of different classes to be treated as objects of a common superclass

b)

To store multiple values in a single variable

c)

To execute code faster

d)

To prevent code duplication

11.

True or False: Running the following code will print Parent to the output.

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

(a)  

12.

True or False: In Python, you can access a parent class's method from a child class using the super() function.

a)

False

b)

True

13.

Suppose you have a Parent class and a Child class, and both have a show_info() method. If you create a Child object and call show_info(), does it run the Child's version of the method?

a)

True

b)

False

14.

In programming, if a child class does not write its own version of a method, will it use the method from the parent class?

a)

TRUE

b)

FALSE

15.

In Python, does using del on an object always remove it from memory immediately?

a)

TRUE

b)

FALSE

16.

True or False: Polymorphism allows different classes to implement methods with the same name, enabling them to be called in a uniform way.

a)

False

b)

True

17.

True or False: In Python, double underscores (e.g., __var) are used to name-mangle attributes to make them harder to access from outside the class.

a)

False

b)

True

18.

Which of the following best describes inheritance in object-oriented programming?

a)

Creating new classes from existing ones

b)

Hiding data from outside access

c)

Executing code line by line

d)

Storing data in a database