Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python_OOPs 1

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is a Python class?

a)

A function to create an object.

b)

A template (blueprint) for creating objects.

c)

A procedure related to an object.

d)

A process that repeats are directed.

2.

What is the keyword to create a class?

a)

import

b)

__int__

c)

class

d)

def

3.

Identify the first statement that creates a class named Employee.

a)

class Employee():

b)

Class Employee:

c)

class employee:

d)

class Employee:

4.

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

a)

instantiation

b)

declare

c)

iteration

d)

initialize

5.

Identify the code that properly creates an instance of a class named Car.

a)

camero.car(make, model)

b)

tesla = car.make()

c)

mustang = Car(make,model)

d)

porsche = car.make.model()

6.

Identify the initialization method for a Car class.

a)

class init(self, make, model):

b)

class__init__:

c)

def __init__(self, make, model):

d)

def __init__(self, make, model):

7.

Identify the code that properly accesses an engine_sound() method in a Car class.

a)

porsche.engine_sound()

b)

mustang = engine_sound()

c)

engine_sound(tesla):

d)

engine_sound.Car(camaro)

8.

Identify the keyword that accesses an instance's attributes when three objects are created.

a)

inheritance

b)

class

c)

__init__

d)

self

9.

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

a)

True

b)

False

c)

Occasionally

d)

Depending on instantiation

10.

What are class variables?

a)

Variables with a sense of style

b)

Variables that apply to all instances of the class

c)

Variables that change with every instance of the class

d)

Integers

11.

Do you think a variable to store a car's value would be a class or instance variable?

a)

Class

b)

Instance

12.

What does __init__ do?

a)

Constructs the instance

b)

Initialize the instance values

c)

Calls the Super class

d)

Creates a circle

13.

Getters and setters

a)

Are important for class incapsulation

b)

Are important to add each data member of the class

c)

Are replaced by the @property decorator in Python

d)

Are replaced by the @classmethod in Python

14.

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?

a)

7

b)

5

c)

3

d)

4

15.

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.

a)

SolarSystem

b)

Planet

c)

Galaxy

d)

Universe

16.

Which statement is not true?

a)

Inheritance tree describes the hierarchy between base and derived classes.

b)

A derived class can access the attributes of all of its base classes via normal attribute reference operations

c)

A derived class inherits the attributes of the base class, and then adds additional attributes

d)

When adding a new derived class, a programmer has to change the base class as well.

17.

A derived class may define a method having the same name as the base class means that:

a)

a derived class method overrides the method of the base class

b)

a base class method overrides the method of the derived class.

c)

the functionality of the method is the same in both derived and base class.

d)

a derived class method overloads the method of the base class.

18.

Identify which relationship of the everyday items is a has-a relationship.

a)

Baseball/Sport

b)

Truck/Vehicle

c)

University/Library

d)

Aspirin/Medicine

19.

Identify which relationship of the everyday items is an is-a relationship.

a)

Basketball/Sport

b)

Car/Transmission

c)

Calculator/Display

d)

Pizza/Topping

20.

Which is an example of inheritance?

a)

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 = ''

b)

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 =''

c)

class Garden:

def __init__(self):

self.name = ''

class Trees:

def __init__(self):

self.name = ''

self.type = ''

self.number = ''

d)

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 = ''