wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Exceptions and Classes

Total questions: 21

Worksheet time: 18mins

Name
Class
Date
1.

What's the use of try-except in Python?

a)

Nothing.

b)

Execute code if a condition is met.

c)

Error handling.

2.

What's a Python class?

a)

A function to create an object.

b)

A procedure related to an object.

c)

A template (blueprint) for creating objects.

3.

When will the else part of try-except-else be executed?

a)

Always.

b)

When an exception occurs.

c)

Never.

d)

When an exception does not occur.

4.

Identify the term that describes the creation of a new object.

a)

Declare.

b)

Iteration.

c)

Instantiation.

d)

initialize.

5.

When is the finally block executed?

a)

When an exception occurs.

b)

Always.

c)

When an exception doesn't occur.

d)

Never.

6.

Identify the code that properly creates an instance of a cass named Vehicle.

a)

bus.Vehicle(wheels, color)

b)

car = vehicle.create()

c)

bike = Vehicle(2, "red")

d)

bike = Vehicle(wheels, color)

7.

Can one except block handle multiple exceptions?

a)

Yes.

b)

Maybe.

c)

No.

8.

Which of the following is correct regarding exception:

a)

That occurs after execution.

b)

That occurs during execution

c)

That occurs before execution

d)

That occurs any time.

9.

Identify the initialization method for a Vehicle class.

a)

function Vehicle(wheels, color) {

this.wheels = wheels;

this.color = color;

}

b)

Vehicle(int w,

String c){

wheels = w;

color = c;

}

c)

public Vehicle(int w, string c)

{

Wheels = w;

Color = c;

}

d)

def __init__(self, w, c):

self.wheels = w

self.color = c

10.

Identify the code that properly accesses a pedal() method in a Bike class.

a)

pedal().bike_1

b)

bike_1 = pedal()

c)

bike_1.pedal()

d)

pedal(bike_1)

11.

Exception handling in Python is done using _ blocks

a)

except

b)

finally

c)

else

d)

try

12.

Inheritance can only be applied between one sub class one super class.

a)

True.

b)

Occasionally.

c)

False.

d)

Depending on instantiation.

13.

What's an attribute?

a)

Something that describes an object.

b)

An action that an object can do.

14.

What term defines that an object can be an attribute of a class?

a)

Inheritance.

b)

association

c)

composition

d)

aggregation

15.

What term defines that the attributes of an object can be attributes of a class?

a)

Inheritance.

b)

Composition.

c)

Association.

d)

Aggregation.

16.

What's encapsulation?

a)

It's puts restrictions on accessing variables and methods directly.

b)

It's removing restrictions on direct access to variables and methods.

c)

It's a decorator that modifies methods.

d)

It's a method to hide attributes.

17.

You can have the same method several times in a class with the difference that the number of parameters changes.

a)

True.

b)

False.

18.

Can a parent class method be overridden in child classes?

a)

True.

b)

False.

19.

'@property' is for:

a)

Set an attribute.

b)

Get an attribute.

c)

Delete an attribute.

20.

Create a class with method overloading.

4 lines
21.

Did you enjoy the course?

a)

Yay!

b)

Nay!