Font size
WorksheetsExceptions and Classes
Total questions: 21
Worksheet time: 18mins
What's the use of try-except in Python?
Nothing.
Execute code if a condition is met.
Error handling.
What's a Python class?
A function to create an object.
A procedure related to an object.
A template (blueprint) for creating objects.
When will the else part of try-except-else be executed?
Always.
When an exception occurs.
Never.
When an exception does not occur.
Identify the term that describes the creation of a new object.
Declare.
Iteration.
Instantiation.
initialize.
When is the finally block executed?
When an exception occurs.
Always.
When an exception doesn't occur.
Never.
Identify the code that properly creates an instance of a cass named Vehicle.
bus.Vehicle(wheels, color)
car = vehicle.create()
bike = Vehicle(2, "red")
bike = Vehicle(wheels, color)
Can one except block handle multiple exceptions?
Yes.
Maybe.
No.
Which of the following is correct regarding exception:
That occurs after execution.
That occurs during execution
That occurs before execution
That occurs any time.
Identify the initialization method for a Vehicle class.
function Vehicle(wheels, color) {
this.wheels = wheels;
this.color = color;
}
Vehicle(int w,
String c){
wheels = w;
color = c;
}
public Vehicle(int w, string c)
{
Wheels = w;
Color = c;
}
def __init__(self, w, c):
self.wheels = w
self.color = c
Identify the code that properly accesses a pedal() method in a Bike class.
pedal().bike_1
bike_1 = pedal()
bike_1.pedal()
pedal(bike_1)
Exception handling in Python is done using _ blocks
except
finally
else
try
Inheritance can only be applied between one sub class one super class.
True.
Occasionally.
False.
Depending on instantiation.
What's an attribute?
Something that describes an object.
An action that an object can do.
What term defines that an object can be an attribute of a class?
Inheritance.
association
composition
aggregation
What term defines that the attributes of an object can be attributes of a class?
Inheritance.
Composition.
Association.
Aggregation.
What's encapsulation?
It's puts restrictions on accessing variables and methods directly.
It's removing restrictions on direct access to variables and methods.
It's a decorator that modifies methods.
It's a method to hide attributes.
You can have the same method several times in a class with the difference that the number of parameters changes.
True.
False.
Can a parent class method be overridden in child classes?
True.
False.
'@property' is for:
Set an attribute.
Get an attribute.
Delete an attribute.
Create a class with method overloading.
Did you enjoy the course?
Yay!
Nay!
