+ 3

Is this the correct way to inherit y? Also how do i make B inherit a method like sum()?

https://code.sololearn.com/cMPthM7EJLCU/?ref=app

3rd Apr 2022, 2:22 PM
Lenoname
4 Réponses
+ 3
#Yes class A: def __init__(self, x, y, f) : self.x = x self.y = y self.f = f def sum(self) : return self.x + self.y + self.f class B(A) : def __init__(self,y): # correction super().__init__(y,y,y) print(B(5).sum())
3rd Apr 2022, 2:35 PM
Jayakrishna 🇮🇳
+ 3
Yes. You have __inti__(self, y) so need one argument for y. And it is passed to super class init, creates an object of B class. Now you can access sum() of A class, by inheritance, which returns 5+5+5 hope it helps..
3rd Apr 2022, 2:45 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 Whats 5? Is it for y?
3rd Apr 2022, 2:39 PM
Lenoname