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
...
Log in to ExamTopics
Sign in:
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.
flthymcnsty
1 month ago