exam questions

Exam PCAP-31-03 All Questions

View all questions & answers for the PCAP-31-03 exam

Exam PCAP-31-03 topic 1 question 90 discussion

Actual exam question from Python Institute's PCAP-31-03
Question #: 90
Topic #: 1
[All PCAP-31-03 Questions]

What is the expected behavior of the following code?

  • A. it outputs 0
  • B. it outputs 1
  • C. it raises an exception
  • D. it outputs 2
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
flthymcnsty
1 month ago
Selected Answer: C
Explanation: Step-by-Step Breakdown: Class Definitions: Super: Super defines two methods: make(self) is an empty method (pass). doit(self) calls self.make(). Sub_A: Sub_A inherits from Super and overrides the make(self) method to return 1. Sub_B: Sub_B inherits from Super but does not override the make(self) method, so it uses the unimplemented make method from Super. Object Instantiation and Method Calls: a = Sub_A() and b = Sub_B(): Creates an instance of each respectively. a.doit(): Calls doit() on the Sub_A instance. Inside doit(), it calls self.make(), which resolves to Sub_A.make(). This method returns 1. b.doit(): Calls doit() on the Sub_B instance. Inside doit(), it calls self.make(). Since Sub_B does not override make(), the call resolves to Super.make(), which is not implemented (pass). This causes Super.make() to implicitly return None. In Python, adding an integer (1) to None is invalid and raises a TypeError. The correct answer is: C. it raises an exception
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago