WorksheetsOOPS Part 2 Quizs
Total questions: 18
Worksheet time: 9mins
True or False: The following line of code will delete the object my_student from memory.del my_student
(a)
In Python, you can use the keyword private to hide an attribute from outside access. Is this statement true or false?
class MyClass:
private_var = 10
True
False
Encapsulation in programming means keeping an object's data private so that it can't be changed directly from outside the object. Is this true or false?
True
False
True or False: In Python, if you create a class B that inherits from class A, and class A has a variable x = 1, then creating an object of B and printing b.x will output 1.
Test it online:class A:
x = 1
class B(A):
pass
b = B()
print(b.x)
(a)
True or False: In the following code, the output will be B because the who method in class B overrides the one in class A.class A:
def who(self):
print("A")
class B(A):
def who(self):
print("B")
b = B()
b.who()
(a)
In Python, which symbol is commonly used to indicate that an attribute is intended to be private?
_ (single underscore)
$ (dollar sign)
# (hash)
@ (at symbol)
Which of the following is NOT a feature of object-oriented programming?
Encapsulation
Inheritance
Compilation
Polymorphism
In programming, does method overriding mean that a child class creates a method with the same name as the parent class, but with different code?
TRUE
FALSE
Which keyword is used in Python to refer to the parent class when calling its methods from a child class?
super()
parent()
base()
main()
In object-oriented programming, what is the main purpose of polymorphism?
To allow objects of different classes to be treated as objects of a common superclass
To store multiple values in a single variable
To execute code faster
To prevent code duplication
True or False: Running the following code will print Parent to the output.class Parent:
def show(self):
print("Parent")
class Child(Parent):
pass
c = Child()
c.show()
(a)
True or False: In Python, you can access a parent class's method from a child class using the super() function.
False
True
Suppose you have a Parent class and a Child class, and both have a show_info() method. If you create a Child object and call show_info(), does it run the Child's version of the method?
True
False
In programming, if a child class does not write its own version of a method, will it use the method from the parent class?
TRUE
FALSE
In Python, does using del on an object always remove it from memory immediately?
TRUE
FALSE
True or False: Polymorphism allows different classes to implement methods with the same name, enabling them to be called in a uniform way.
False
True
True or False: In Python, double underscores (e.g., __var) are used to name-mangle attributes to make them harder to access from outside the class.
False
True
Which of the following best describes inheritance in object-oriented programming?
Creating new classes from existing ones
Hiding data from outside access
Executing code line by line
Storing data in a database
