Python Programming Multiple Choice Question -
Inheritance

This section focuses on the "Inheritance" in Python programming. These Multiple Choice Questions (mcq) should be practiced to improve the Python programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. What is true about Inheritance in Python?

A. Inheritance is the capability of one class to derive or inherit the properties from another class.
B. It represents real-world relationships well.
C. It provides reusability of a code.
D. All of the above

View Answer


2. When a child class inherits from only one parent class, it is called?

A. single inheritance
B. singular inheritance
C. Multiple inheritance
D. Multilevel inheritance

View Answer


3. Which inheritance is a blend of more than one type of inheritance?

A. single inheritance
B. Hybrid inheritance
C. Multiple inheritance
D. Multilevel inheritance

View Answer


4. Parent class is the class being inherited from, also called?

A. derived class
B. Child class
C. Hybrid class
D. base class

View Answer


5. The child's __init__() function overrides the inheritance of the parent's __init__() function.

A. TRUE
B. FALSE
C. Can be true or false
D. Can not say

View Answer


6. __________function that will make the child class inherit all the methods and properties from its parent

A. self
B. __init__()
C. super
D. pass 

View Answer


7. Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write?

A. A.__init__(self)
B. B.__init__(self)
C. A.__init__(B)
D. B.__init__(A)

View Answer


8. What does built-in function type do in context of classes?

A. Determines the object name of any value
B. Determines the class name of any value
C. Determines class description of any value
D. Determines the file name of any value

View Answer


9. Which of the following statements is false?

A. A non-private method in a superclass can be overridden
B. A derived class is a subset of superclass
C. The value of a private variable in the superclass can be changed in the subclass
D. When invoking the constructor from a subclass, the constructor of superclass is automatically invoked

View Answer


10. What will be output for the folllowing code?

class A:
    def __init__(self, x= 1):
        self.x = x
class der(A):
    def __init__(self,y = 2):
        super().__init__()
        self.y = y
def main():
    obj = der()
    print(obj.x, obj.y)
main()

A. Error, the syntax of the invoking method is wrong
B. The program runs fine but nothing is printed
C. 1 0
D. 1 2

View Answer




Discussion



* You must be logged in to add comment.