Please, explain inheritance in a simple way | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please, explain inheritance in a simple way

8th Oct 2020, 7:53 AM
Sara Getnet
Sara Getnet - avatar
2 Answers
+ 1
class A: def __init__(self): self.value = 5 def hello_msg(self): print("Hello!") class B(A): def __init__(self): super().__init__() # calls to A's method and B's inherited method A().hello_msg() B().hello_msg() # output Hello! Hello!
8th Oct 2020, 9:50 AM
Slick
Slick - avatar
- 1
Class A Def method (self) Print (1) Class B Def method (self) Print(2) B(). Method() do it
8th Oct 2020, 8:28 AM
Sara Getnet
Sara Getnet - avatar