0% found this document useful (0 votes)
26 views6 pages

Python Inheritance and Loop MCQs

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

Python Inheritance and Loop MCQs

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

---

🔹 Python Inheritance + Loop MCQs

Q1. Which keyword is used for inheritance in Python?

a) extends

b) inherits

c) class Child(Parent)

d) super

✅ Answer: c) class Child(Parent)

---

Q2. How do you call the parent class constructor inside a child class?

a) Parent.__init__(self)

b) super().__init__()

c) Both a and b

d) None

✅ Answer: c) Both a and b

---

Q3. Which attribute shows the Method Resolution Order (MRO) of a class?

a) __dict__

b) __mro__
c) __bases__

d) __class__

✅ Answer: b) __mro__

---

Q4. What will the loop print?

class A:

def show(self):

return "A"

class B(A):

def show(self):

return "B"

objs = [A(), B()]

for obj in objs:

print([Link](), end=" ")

a) A B

b) B A

c) A A

d) Error

✅ Answer: a) A B
---

Q5. In multiple inheritance, Python resolves methods using:

a) Depth-first search

b) Breadth-first search

c) Method Resolution Order (MRO)

d) Random order

✅ Answer: c) Method Resolution Order (MRO)

---

Q6. Which function checks if an object belongs to a class or subclass?

a) issubclass()

b) isinstance()

c) type()

d) id()

✅ Answer: b) isinstance()

---

Q7. What does this code output?

class P:

def __init__(self):
self.x = 1

class C(P):

def __init__(self):

super().__init__()

self.y = 2

obj = C()

for k, v in obj.__dict__.items():

print(k, v, end="; ")

a) x 1; y 2;

b) y 2;

c) x 1;

d) Error

✅ Answer: a) x 1; y 2;

Q8. What will this code print?

Class Parent:

Def greet(self):

Return “Hello Parent”

Class Child(Parent):

Pass

Objs = [Parent(), Child()]

For obj in objs:


Print([Link](), end=” | “)

a) Hello Parent | Hello Child |

b) Hello Parent | Hello Parent |

c) Error

d) None

✅ Answer: b) Hello Parent | Hello Parent |

Q9. Which statement is true about super() in Python?

a) It directly calls the parent class by name.

b) It calls the next class in MRO order.

c) It only works in single inheritance.

d) It skips the parent constructor.

✅ Answer: b) It calls the next class in MRO order.

Q10. What will the loop output?

Class A:

Def show(self):

Return “A”

Class B(A):

Def show(self):
Return super().show() + “B”

For obj in [B(), A()]:

Print([Link](), end=” “)

a) AB A

b) A A

c) B A

d) Error

✅ Answer: a) AB A

You might also like