wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Inheritance and Methods Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following statements correctly describes inheritance in Python?

a)

It allows a class to create multiple instances.

b)

It allows a class to hide its attributes and methods.

c)

It allows a class (subclass) to inherit attributes and methods from another class (superclass), promoting code reuse.

d)

It allows a class to override its parent class methods without inheriting them.

2.

Which of the following is not a type of inheritance?

a)

Double-level

b)

Multi-level

c)

Single-level

d)

Multiple

3.

What type of inheritance is illustrated in the following Python code? class A(): pass class B(A): pass class C(B): pass

a)

Multi-level inheritance

b)

Multiple inheritance

c)

Hierarchical inheritance

d)

Single-level inheritance

4.

What is the purpose of the __init__ method in a Python class?

a)

To initialize the class object with default attributes.

b)

To create a new instance of the class.

c)

To define the constructor of the class.

d)

To destroy the class object.

5.

What is the purpose of the "pass" statement in Python?

a)

The "pass" statement is used to indicate methods undefined and will do nothing.

b)

The "pass" statement is used to exit a loop.

c)

The "pass" statement is used to define a class.

d)

The "pass" statement is used to call another method.

6.

Which dunder method is used to implement the behavior of the ' / ' operator in Python?

a)

__div__

b)

__truediv__

c)

__floordiv__

d)

None of these

7.

What is the purpose of the __setattr__ method in Python?

a)

It is used to set the value of an attribute.

b)

It is used to define the behavior of attribute assignment.

c)

It is used to check if an attribute exists.

d)

It is used to delete an attribute.

8.

Which dunder method is used to implement the behavior of the != operator in Python?

a)

__ge__

b)

__eq__

c)

__le__

d)

__ne__

9.

What does the __add__ method do in Python?

a)

It adds two objects together.

b)

It concatenates two objects.

c)

It performs element-wise addition for two objects.

d)

It performs matrix multiplication for two objects.

10.

Which of the following statements about function arguments in Python is true?

a)

All arguments must have default values

b)

Functions cannot have more than one argument

c)

Arguments are passed by value

d)

Arguments can have default values