0% found this document useful (0 votes)
210 views7 pages

Quiz 4.1 OOP - CPE 009 CPE12S1 Object Oriented Programming

This document is a quiz on object-oriented programming concepts in Python. It contains 10 multiple choice questions related to classes, objects, inheritance, and the use of self and special methods like __init__. The student received a score of 8 out of 10 on their first attempt, which took 27 minutes to complete.

Uploaded by

Sonty Balingit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
210 views7 pages

Quiz 4.1 OOP - CPE 009 CPE12S1 Object Oriented Programming

This document is a quiz on object-oriented programming concepts in Python. It contains 10 multiple choice questions related to classes, objects, inheritance, and the use of self and special methods like __init__. The student received a score of 8 out of 10 on their first attempt, which took 27 minutes to complete.

Uploaded by

Sonty Balingit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

4/6/22, 10:55 AM Quiz 4.

1 OOP: CPE 009-CPE12S1 - Object Oriented Programming

Quiz 4.1 OOP


Due
Apr 6 at 11:59pm
Points
10
Questions
10
Available
Apr 4 at 12am - Apr 6 at 11:59pm
3 days
Time Limit
30 Minutes

Attempt History
Attempt Time Score
LATEST Attempt 1
27 minutes 8 out of 10


Correct answers are hidden.

Score for this quiz:


8 out of 10
Submitted Apr 6 at 10:55am
This attempt took 27 minutes.

Question 1 1
/ 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.

 
The program will run but will not display anything.

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

https://tip.instructure.com/courses/29905/quizzes/378535 1/7
4/6/22, 10:55 AM Quiz 4.1 OOP: CPE 009-CPE12S1 - Object Oriented Programming

 
The program will output "Default Name"

Question 2 1
/ 1 pts

Which of the following is incorrect about the use of the keyword self in
Python?

 
self refers to the instance of the class.

 
Not putting self on a variable inside a method will cause a syntax error.

 
self is a required parameter in all methods in a class otherwise, methods
without self when called outside of the class will cause an error.

 
self differentiates each variable per instance.

Incorrect
Question 3 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

https://tip.instructure.com/courses/29905/quizzes/378535 2/7
4/6/22, 10:55 AM Quiz 4.1 OOP: CPE 009-CPE12S1 - Object Oriented Programming

   def start(self):

       self.is_enginerunning = True

   def stop(self):

       self.is_enginerunning = False

class Class1Vehicle():

   pass

vehicle1 = Class1Vehicle()

What type of Inheritance is applied to this example?

 
Single Inheritance

 
Multilevel Inheritance

 
Multiple Inheritance

 
None

Question 4 1
/ 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

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")

https://tip.instructure.com/courses/29905/quizzes/378535 3/7
4/6/22, 10:55 AM Quiz 4.1 OOP: CPE 009-CPE12S1 - Object Oriented Programming

officer1.initiateEvent("General Assembly")

print(officer1.stu_num)

What will be the output of the program?

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

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

 
0

 
None

Question 5 1
/ 1 pts

The constructor function is defined with the keyword _________?

 
__init__

 
init__

 
__init

 
_init_

Question 6 1
/ 1 pts

A ________ is a template or blueprint from which objects can be


instantiated from.

class

https://tip.instructure.com/courses/29905/quizzes/378535 4/7
4/6/22, 10:55 AM Quiz 4.1 OOP: CPE 009-CPE12S1 - Object Oriented Programming

Question 7 1
/ 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 = 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

 
True

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

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

https://tip.instructure.com/courses/29905/quizzes/378535 5/7
4/6/22, 10:55 AM Quiz 4.1 OOP: CPE 009-CPE12S1 - Object Oriented Programming

Question 8 1
/ 1 pts

A constructor function may or may not be added to a class as it is added


automatically by default.

 
True

 
False

Question 9 1
/ 1 pts

Constructors are used to

 
Modify the object

 
Create the object

 
Initialize an object

 
Create a sub class

Incorrect 0
/ 1 pts
Question 10

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


parts: Its _____________ and Methods.

Class

https://tip.instructure.com/courses/29905/quizzes/378535 6/7
4/6/22, 10:55 AM Quiz 4.1 OOP: CPE 009-CPE12S1 - Object Oriented Programming

Quiz Score:
8 out of 10

https://tip.instructure.com/courses/29905/quizzes/378535 7/7

You might also like