Step by Step Explanation:
Step 1: Define Class A
A class named A is created.
Inside A, we define a method show():
When called, this method returns the string "A".
Any object of A can call show() and get "A".
class B(A):
pass
Step 2: Define Class B (Inheritance)
B is inheriting from A, meaning B gets all the attributes and methods of A.
The keyword pass means no additional methods or properties are added to B.
Since B does not have its own show() method, it will inherit the method from A.
print(B().show())
Step 3: Create an Object of B and Call show()
B() creates an instance of class B.
B().show() calls the show() method.
Since B does not have a show() method, it looks in class A (its parent class).
The show() method in A is executed, returning "A".
The print() function prints the returned value.
Final Output
A
0 Comments:
Post a Comment