wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

OOPS Part 2

Total questions: 20

Worksheet time: 15mins

Name
Class
Date
1.

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

2.

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

3.

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

4.

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

a)

TRUE

b)

FALSE

5.

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

6.

Which of the following shows how to make a Dog class inherit from an Animal class in Python?

  1. class Dog(Animal):
    pass
  2. class Animal(Dog):
    pass
  3. class Dog:
    pass

Choose the correct answer.

4 lines
7.

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

8.

Why do we use super().__init__() in a child class in Python?

  • A) To call the parent class constructor
  • B) To delete the parent class
  • C) To create a new method
  • D) To end the program

Choose the correct option and write a small code to test your answer.

4 lines
9.

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)  

10.

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

(a)  

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 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)  

13.

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

a)

Encapsulation

b)

Inheritance

c)

Compilation

d)

Polymorphism

14.

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)

15.

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

16.

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

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.

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

19.

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()

20.

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