diff --git a/Basics/Hindi/17_inheritance/inheritace.py b/Basics/Hindi/17_inheritance/inheritace.py index a90123c8..d64efa1e 100644 --- a/Basics/Hindi/17_inheritance/inheritace.py +++ b/Basics/Hindi/17_inheritance/inheritace.py @@ -1,14 +1,22 @@ class Animal: - def __init__(self, living_place): - self.living_place = living_place + def __init__(self, habitat): + self.habitat = habitat + + def print_habitat(self): + print(self.habitat) + + def sound(self): + print("Some Animal Sound") - def printplace(self): - print(self.living_place) class Dog(Animal): - def __init__(self, living_place): - super().__init__(living_place) + def __init__(self): + super().__init__("Kennel") + + def sound(self): + print("Woof woof!") -x = Dog("zoo") -x.printplace() +x = Dog() +x.print_habitat() +x.sound() \ No newline at end of file diff --git a/Basics/Hindi/17_inheritance/inheritance.md b/Basics/Hindi/17_inheritance/inheritance.md index c8f2fd8c..925e0945 100644 --- a/Basics/Hindi/17_inheritance/inheritance.md +++ b/Basics/Hindi/17_inheritance/inheritance.md @@ -1,21 +1,21 @@ ## Exercise: Inheritance -1. create inheritance using animal dog relation. +1. create inheritance using animal Dog relation. ``` for example, - animal and dog both has same living_place so create a method for living_place + Animal and Dog both has same habitat so create a method for habitat ``` 2. use super() constructor for calling parent constructor. ``` -class animal: +class Animal: #code -class dog(animal): - super()-it refers animal class,now you can call animal's methods. +class Dog(Animal): + super()-it refers Animal class,now you can call Animal's methods. ``` [Solution](https://github.com/codebasics/py/blob/master/Basics/python_basics/17_inheritance/17_inheritance.py) diff --git a/Basics/Hindi/18_multiple_inheritance/multiple_inheritance.py b/Basics/Hindi/18_multiple_inheritance/multiple_inheritance.py index 5b7ac964..57be8094 100644 --- a/Basics/Hindi/18_multiple_inheritance/multiple_inheritance.py +++ b/Basics/Hindi/18_multiple_inheritance/multiple_inheritance.py @@ -1,20 +1,23 @@ -class Teacher(): - def teachers_action(self): - print('I can teach') +class Teacher: + def teachers_action(self): + print("I can teach") -class Engineer(): +class Engineer: def Engineers_action(self): - print('I can code') + print("I can code") -class Youtuber(): + +class Youtuber: def youtubers_action(self): - print('I can code and teach') + print("I can code and teach") + + +class Person(Teacher, Engineer, Youtuber): + pass -class Person(Teacher, Engineer, Youtuber): - pass -coder = Person() +coder = Person() coder.teachers_action() coder.Engineers_action() coder.youtubers_action()