My Report

Python OOP Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which of the following best describes inheritance?

2. Which of the following is not a type of inheritance?

3. 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?

4. All subclasses are a subtype in object-oriented programming.

5. What will be the output of the following Python code?

class A():
    def disp(self):
        print("A disp()")
class B(A):
    pass
obj = B()
obj.disp()

6. When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword is used.

7. What does built-in function help do in context of classes?

8. What will be the output of the following Python code?

class A:
    def one(self):
        return self.two()
    
    def two(self):
        return 'A'
    
class B(A):
    def two(self):
        return 'B'
obj1=A()
obj2=B()
print(obj1.two(),obj2.two())

9. Which of the following statements is wrong about inheritance?

10. What will be the output of the following Python code?

class Test:
    def __init__(self):
        self.x = 0
class Derived_Test(Test):
    def __init__(self):
        self.y = 1
def main():
    b = Derived_Test()
    print(b.x,b.y)
main()

11. What will be the output of the following Python 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()

12. 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()

13. What type of inheritance is illustrated in the following Python code?

class A():
    pass
class B():
    pass
class C(A,B):
    pass

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

15. What will be the output of the following Python code?

class Test:
    def __init__(self):
        self.x = 0
class Derived_Test(Test):
    def __init__(self):
        Test.__init__(self)
        self.y = 1
def main():
    b = Derived_Test()
    print(b.x,b.y)
main()

 

Start practicing “1000 MCQs on Python”, and once you are ready, you can take tests on all topics by attempting our “Python Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.