WorksheetsPython_OOPs 1
Total questions: 20
Worksheet time: 10mins
What is a Python class?
A function to create an object.
A template (blueprint) for creating objects.
A procedure related to an object.
A process that repeats are directed.
What is the keyword to create a class?
import
__int__
class
def
Identify the first statement that creates a class named Employee.
class Employee():
Class Employee:
class employee:
class Employee:
Identify the term that describes the creation of a new object.
instantiation
declare
iteration
initialize
Identify the code that properly creates an instance of a class named Car.
camero.car(make, model)
tesla = car.make()
mustang = Car(make,model)
porsche = car.make.model()
Identify the initialization method for a Car class.
class init(self, make, model):
class__init__:
def __init__(self, make, model):
def __init__(self, make, model):
Identify the code that properly accesses an engine_sound() method in a Car class.
porsche.engine_sound()
mustang = engine_sound()
engine_sound(tesla):
engine_sound.Car(camaro)
Identify the keyword that accesses an instance's attributes when three objects are created.
inheritance
class
__init__
self
Inheritance can only be applied between one sub class and one super class.
True
False
Occasionally
Depending on instantiation
What are class variables?
Variables with a sense of style
Variables that apply to all instances of the class
Variables that change with every instance of the class
Integers
Do you think a variable to store a car's value would be a class or instance variable?
Class
Instance
What does __init__ do?
Constructs the instance
Initialize the instance values
Calls the Super class
Creates a circle
Getters and setters
Are important for class incapsulation
Are important to add each data member of the class
Are replaced by the @property decorator in Python
Are replaced by the @classmethod in Python
Class Healthcare has the methods Pharmacy() and Labs(). Class Hospitals is derived from Healthcare and has the methods Doctor(), Patients(), and Nurses(). Afterh = Hospitals()executes, how many different methods can object h call, ignoring constructors?
7
5
3
4
Identify the base class for the other classes in the given statement.
Planet is derived from SolarSystem; SolarSystem is derived from Galaxy; Galaxy is derived from Universe.
SolarSystem
Planet
Galaxy
Universe
Which statement is not true?
Inheritance tree describes the hierarchy between base and derived classes.
A derived class can access the attributes of all of its base classes via normal attribute reference operations
A derived class inherits the attributes of the base class, and then adds additional attributes
When adding a new derived class, a programmer has to change the base class as well.
A derived class may define a method having the same name as the base class means that:
a derived class method overrides the method of the base class
a base class method overrides the method of the derived class.
the functionality of the method is the same in both derived and base class.
a derived class method overloads the method of the base class.
Identify which relationship of the everyday items is a has-a relationship.
Baseball/Sport
Truck/Vehicle
University/Library
Aspirin/Medicine
Identify which relationship of the everyday items is an is-a relationship.
Basketball/Sport
Car/Transmission
Calculator/Display
Pizza/Topping
Which is an example of inheritance?
class Library:
def __init__(self):
self.name = ''
class Books:
def __init__(self):
self.number = ''
class Pages:
def __init__(self):
self.number = ''
self.words = ''
self.paragraphs = ''
class Car:
def __init__(self):
self.type = ''
class Boat:
def __init__(self):
self.model = ''
class Engine:
def __init__(self):
self.model = ''
self.type = ''
self.power =''
class Garden:
def __init__(self):
self.name = ''
class Trees:
def __init__(self):
self.name = ''
self.type = ''
self.number = ''
class Elements:
def __init__(self):
self.name = ''
class Metal(Elements):
def __init__(self):
Elements.__init__(self)
self.mass = ''
self.atomicNumber = ''
class NonMetal(Elements):
def __init__(self):
Elements.__init__(self)
self.mass = ''
self.atomicNumber = ''
