PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 94


Assuming that the following inheritance set is in force, which of the following classes are declared properly? (Choose two.)

Show Answer
Correct Answer: AD

The given options involve multiple inheritance structures. For a class definition with multiple inheritance to be correct in Python, the parent classes must be inherited in an order that preserves the method resolution order (MRO). The following class declarations are proper: class Class_4(D,A): pass and class Class_1(C,D): pass. In these correct declarations, the MRO can be successfully determined without any inconsistencies. The other options, class Class_3(A,C): pass and class Class_2(B,D): pass, would raise a TypeError because they result in conflicting MROs where a parent class is listed before its subclass, leading to ambiguity.

Discussion

10 comments
Sign in to comment
MTLEOptions: AC
Apr 25, 2022

A can't be declared from C as A is superclass to C, same goes to B and D. Answer is correct

Janpcap123Options: AD
Sep 1, 2023

CaptinPirate answer is answer A and answer D, this will save you checking his/her/they link

macxszOptions: AD
May 4, 2022

only corrects are: A. class Class_4(D,A): pass D. class Class_1(C,D): pass

BokaOptions: AB
Aug 10, 2022

How class Class_1(C,D): pass is correct here? D is not sub class of C

CaptainPirate
Aug 29, 2023

Ok guys.Here is your answer.I only typed it in VSSCODE and here it is: https://drive.google.com/file/d/122fvfA91ZyKcsq7qlaBQXYcGH0x7e9Ja/view?usp=sharing

erikkkOptions: BC
Oct 26, 2021

shouldn't this be BC?

mouhsini
Oct 27, 2021

Can't be B, class A shouldn't be before class C, because class C is a subclass of class A. The order left and right is important in python.

ruydrigo
Jan 14, 2022

Anyone can please explain this questions?

macxsz
May 4, 2022

On multiple inheretance, the Parent cannot be declared before the child: https://www.datacamp.com/community/tutorials/super-multiple-inheritance-diamond-problem

Raymond91Options: BD
Jul 19, 2023

Why is the corract answer not Class(D,C): pass ?? D -> B -> A C -> A I do not understand why the correct answer is Class(C,D): pass Can someone please explain? Is that because in the inheritance class B cannot be invoked before class C is invoked which is why it's Class(C,D): pass C -> A D -> B -> A (class B invoked later on as it is initialized earlier than class C)

seaverickOptions: AD
Jan 28, 2024

class A: pass class B(A): pass class C(A): pass class D(B): pass class Class_4(D,A): pass #class Class_3(A,C): pass#TypeError: Cannot create a consistent method resolution order (MRO) for bases A, C #class Class_2(B,D): pass#TypeError: Cannot create a consistent method resolution order (MRO) for bases A, C class Class_1(C,D): pass Ans is A,D

Damon54Options: AC
Feb 7, 2024

TypeError: Cannot create a consistent method resolution order (MRO) for bases A, C TypeError: Cannot create a consistent method resolution order (MRO) for bases B, D