Python Programming (2180711) MCQs

MCQs of Classes and Object-Oriented Programming

Showing 11 to 20 out of 45 Questions
11.
What are the methods which begin and end with two underscore characters called?
(a) Special methods
(b) In-built methods
(c) User-defined methods
(d) Additional methods
Answer:

Option (a)

12.
Special methods need to be explicitly called during object creation.
(a) TRUE
(b) FALSE
Answer:

Option (b)

13.
What is hasattr(obj,name) used for?
(a) To access the attribute of the object
(b) To delete an attribute
(c) To check if an attribute exists or not
(d) To set an attribute
Answer:

Option (c)

14.
What is delattr(obj,name) used for?
(a) To print deleted attribute
(b) To delete an attribute
(c) To check if an attribute is deleted or not
(d) To set an attribute
Answer:

Option (b)

15.
__del__ method is used to destroy instances of a class.
(a) TRUE
(b) FALSE
Answer:

Option (a)

16.
What does print(Test.__name__) display (assuming Test is the name of the class)?
(a) ()
(b) Exception is thrown
(c) Test
(d) __main__
Answer:

Option (c)

17.
Which of the following best describes inheritance?
(a) Ability of a class to derive members of another class as a part of its own definition
(b) Means of bundling instance variables and methods in order to restrict access to certain class members
(c) Focuses on variables and passing of variables to functions
(d) Allows for implementation of elegant software that is well designed and easily modified
Answer:

Option (a)

18.
Which of the following statements is wrong about inheritance?
(a) Protected members of a class can be inherited
(b) The inheriting class is called a subclass
(c) Private members of a class can be inherited and accessed
(d) Inheritance is one of the features of OOP
Answer:

Option (c)

19.
What will be the output of the following Python code?
class Demo:
    def __new__(self):
        self.__init__(self)
        print(""Demo's __new__() invoked"")
    def __init__(self):
        print(""Demo's __init__() invoked"")
class Derived_Demo(Demo):
    def __new__(self):
        print(""Derived_Demo's __new__() invoked"")
    def __init__(self):
        print(""Derived_Demo's __init__() invoked"")
def main():
    obj1 = Derived_Demo()
    obj2 = Demo()
main()
(a)
Derived_Demo’s __init__() invoked
Derived_Demo's __new__() invoked
Demo's __init__() invoked
Demo's __new__() invoked
(b)
Derived_Demo's __new__() invoked
Demo's __init__() invoked
Demo's __new__() invoked
(c)
Derived_Demo's __new__() invoked
Demo's __new__() invoked
(d)
Derived_Demo’s __init__() invoked
Demo's __init__() invoked
Answer:

Option (b)

20.
All subclasses are a subtype in object-oriented programming.
(a) TRUE
(b) FALSE
Answer:

Option (b)

Showing 11 to 20 out of 45 Questions