PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 101


Assuming that the following piece of code has been executed successfully, which of the expressions evaluate to True? (Choose two.)

Show Answer
Correct Answer: AB

The expression 'isinstance(obj_b, A)' evaluates to True because class B inherits from class A, making an instance of B also an instance of A. The expression 'A.VarA == 1' is True because within the definition of class A, 'VarA' is explicitly set to 1. Thus, these two expressions are correct. The other options are incorrect because 'obj_a is obj_aa' evaluates to False since 'is' checks for identity, and 'obj_a' and 'obj_aa' are two separate instances. 'B.VarA == 1' is False because in class B, 'VarA' is set to 2.

Discussion

11 comments
Sign in to comment
mazimirOptions: AB
Oct 19, 2021

Its: True True False False

Misco33
Nov 6, 2021

That's correct, try this code: class A: VarA = 1 def __init__(self) -> None: self.prop_a=1 class B(A): VarA = 2 def __init__(self) -> None: self.prop_b=2 obj_a = A() obj_aa = A() obj_b=B() obj_bb=B() print(isinstance(obj_b,A)) print(A.VarA==1) print(obj_a is obj_aa) print(B.VarA == 1)

DTL001Options: AB
Dec 19, 2021

The correct answer is AB

macxszOptions: AB
May 4, 2022

A. isinstance (obj_b,A) B. A.VarA == 1

Noarmy315Options: AB
Jan 16, 2022

AB is correct

rocky48Options: AB
Apr 23, 2022

AB is correct

rocky48
Apr 23, 2022

>>> isinstance(obj_b, A) True >>> A.VarA == 1 True >>> obj_a is obj_aa False >>> B.VarA == 1 False

macxszOptions: AB
Apr 29, 2022

A and B are the only True

deckmanOptions: AB
May 11, 2022

A and B are correct ones

blacksmokerrOptions: AB
Jun 5, 2022

this is a,b

JnanadaOptions: AB
Aug 19, 2022

Correct Answer : A,B

9prayerOptions: AB
Feb 5, 2023

Correct Answer : A,B

kontraOptions: AB
Mar 21, 2023

Correct Answer : A,B