You are on page 1of 8

4/22/22, 3:04 AM Quiz 5.

1 Inheritance, Encapsulation, and Abstraction: CPE 009-CPE12S1 - Object Oriented Programming

Quiz 5.1 Inheritance, Encapsulation, and Abstraction


Due
Apr 11 at 11:59pm
Points
10
Questions
10
Available
Apr 11 at 12am - Apr 11 at 11:59pm
about 24 hours
Time Limit
30 Minutes

This quiz was locked Apr 11 at 11:59pm.

Attempt History
Attempt Time Score
LATEST Attempt 1
7 minutes 5 out of 10

Score for this quiz:


5 out of 10
Submitted Apr 11 at 11:30pm
This attempt took 7 minutes.

Question 1 0
/ 1 pts

Given the following Python program below:

class Vehicle():

""" This is a base vehicle class """

   def __init__(self):

       self.wheelno = 2 # default wheel number to be considered a vehicle

       self.weight = 2,722 # in kg (default car weight for a class 1 vehicle)

       self.fueltank_capacity = 7 # default fuel tank capacity must be 7-10


liters

       self.capacity = 1 # all vehicles by default should support 1 passenger

       self.is_enginerunning = False

   def start(self):

       self.is_enginerunning = True

   def stop(self):

       self.is_enginerunning = False

class Class1Vehicle():

   pass

https://tip.instructure.com/courses/29905/quizzes/378522?module_item_id=2516349 1/8
4/22/22, 3:04 AM Quiz 5.1 Inheritance, Encapsulation, and Abstraction: CPE 009-CPE12S1 - Object Oriented Programming

vehicle1 = Class1Vehicle()

What type of Inheritance is applied to this example?

 
Single Inheritance

 
Multiple Inheritance

ou Answered  
Multilevel Inheritance

orrect Answer  
None

Question 2 0
/ 1 pts

Consider the following program with the following codes:

class Person():

   def __init__(self):

       self.__name = "Default Name"

person1 = Person()
print(self.__name)

What is the output of this program? Choose the best answer.

orrect Answer  
The program will output an attribute error because Python could not find an
attribute __name in Person

 
The program will run but will not display anything.

ou Answered  
The program will output "Default Name"

https://tip.instructure.com/courses/29905/quizzes/378522?module_item_id=2516349 2/8
4/22/22, 3:04 AM Quiz 5.1 Inheritance, Encapsulation, and Abstraction: CPE 009-CPE12S1 - Object Oriented Programming

Question 3 1
/ 1 pts

The constructor function is defined with the keyword _________?

 
__init

 
_init_

 
init__

Correct!  
__init__

Question 4 1
/ 1 pts

A ___________ is a subroutine defined within a class to implement a


behaviour. This subroutine can also be referred to as a function within a
class.

Correct!
method

orrect Answers method

Question 5 0
/ 1 pts

Given the following Python program below:

class Vehicle():

""" This is a base vehicle class """

   def __init__(self):

https://tip.instructure.com/courses/29905/quizzes/378522?module_item_id=2516349 3/8
4/22/22, 3:04 AM Quiz 5.1 Inheritance, Encapsulation, and Abstraction: CPE 009-CPE12S1 - Object Oriented Programming

       self.wheelno = 2 # default wheel number to be considered a vehicle

       self.weight = 2722 # in kg (default car weight for a class 1 vehicle)

       self.fueltank_capacity = 7 # default fuel tank capacity must be 7-10


liters

       self.capacity = 1 # all vehicles by default should support 1 passenger

       self.is_enginerunning = False

   def start(self):

       self.is_enginerunning = True

   def stop(self):

       self.is_enginerunning = False

class Class1Vehicle():

   pass

vehicle1 = Class1Vehicle()

vehicle1.start()

print(vehicle1.is_enginerunning)

What will be the output of the following program when it is run?

 
False

ou Answered  
True

orrect Answer  
AttributeError: 'Class1Vehicle' object has no attribute 'start'

 
TypeError: start() takes 0 positional arguments but 1 was given

Question 6 0
/ 1 pts

The following program was executed in Python

class Person():

   def __init__(self):

       self.__name = "Default Name"

https://tip.instructure.com/courses/29905/quizzes/378522?module_item_id=2516349 4/8
4/22/22, 3:04 AM Quiz 5.1 Inheritance, Encapsulation, and Abstraction: CPE 009-CPE12S1 - Object Oriented Programming

person1 = Person()
person2 = Person()
print(person1)

print(person2)

The result showed

<__main__.Person object at 0x00000221EE95ACC8>

<__main__.Person object at 0x00000221EE96C788>

Which of the following statements in the choices is wrong?

ou Answered  
person1 and person2 has the same variable names but the instance is
different.

 
When we create instances, their memory allocations are different meaning
though they are derived from the same class they may take on different
values.

orrect Answer  
Modifying person1's variables will also modify person2's variables because
they were both created from class Person.

 
The memory addresses maybe different but they are derived from the
same class which acts as a template.

Question 7 1
/ 1 pts

Given the following Python program below:

class Student():

   def __init__(self, student_number, name):

https://tip.instructure.com/courses/29905/quizzes/378522?module_item_id=2516349 5/8
4/22/22, 3:04 AM Quiz 5.1 Inheritance, Encapsulation, and Abstraction: CPE 009-CPE12S1 - Object Oriented Programming

      self.stu_number= student_number

      self.stu_name= name

class DSCOfficer(Student):

   def __init__(self, department):

      self.department = department

      self.event_list = []

   def initiateEvent(self, name):

      self.eventlist.append({"name":name})

officer1 = DSCOfficer("CpE")

officer1.initiateEvent("General Assembly")

print(officer1.stu_num)

What will be the output of the program?

 
0

Correct!  
AttributeError: 'DSCOfficer' object has no attribute 'stu_num'

 
None

 
TypeError: initiateEvent() takes 1 positional argument but 2 were given

Question 8 1
/ 1 pts

In Object-Oriented Programming, an object is composed of two main


parts: Its _____________ and Methods.

Correct!
Attributes

orrect Answers Attributes

https://tip.instructure.com/courses/29905/quizzes/378522?module_item_id=2516349 6/8
4/22/22, 3:04 AM Quiz 5.1 Inheritance, Encapsulation, and Abstraction: CPE 009-CPE12S1 - Object Oriented Programming

Question 9 1
/ 1 pts

Given the following Python code:

class Person():

   class_variable = "This is a person class"

   def __init__(self):

       self.__name = "Secret name under an instance"

       global_class_variable = "inside init only"

  def greet():

       print("Hello World!")

person1 = Person()
person1.greet()

What is the output of the code?

Correct!  
TypeError: greet() takes 0 positional arguments but 1 was given

 
AttributeError: 'Person' object has no attribute 'greet'

 
<bound method Person.greet of <__main__.Person object at
0x000001A79201D088>>

 
Hello World

Question 10 0
/ 1 pts

Given the following Python program below:

class Student():

   def __init__(self, student_number, name):

      self.stu_number= student_number

      self.stu_name= name

https://tip.instructure.com/courses/29905/quizzes/378522?module_item_id=2516349 7/8
4/22/22, 3:04 AM Quiz 5.1 Inheritance, Encapsulation, and Abstraction: CPE 009-CPE12S1 - Object Oriented Programming

class DSCOfficer(Student):

   def __init__(self, department):

      self.department = department

      self.event_list = []

   def initiateEvent(self, name):

      self.event_list.append({"name":name})

officer1 = DSCOfficer("CpE")

officer1.initiateEvent("General Assembly")

print(officer1.event_list)

What will be the output of the program?

 
[]

orrect Answer  
[{'name': 'General Assembly'}]

 
TypeError: initiateEvent() takes 1 positional argument but 2 were given

ou Answered  
AttributeError: 'DSCOfficer' object has no attribute 'eventlist'

Quiz Score:
5 out of 10

https://tip.instructure.com/courses/29905/quizzes/378522?module_item_id=2516349 8/8

You might also like