Explanation:
Class A Definition:
A is a class that has a method show() which returns the string "A".
Class B Definition:
B is a subclass of A (class B(A):), meaning B inherits everything from A.
The keyword pass is used, which means B does not introduce any new attributes or methods—it simply inherits from A.
Creating an Instance of B:
B() creates an object of class B.
Calling show() on an Instance of B:
print(B().show()):
Since B does not have its own show() method, it looks up the method in its parent class (A).
The show() method of A is executed, returning "A".
Output:
A
0 Comments:
Post a Comment