Skip to content

Commit

Permalink
Edited: 17_18
Browse files Browse the repository at this point in the history
  • Loading branch information
d_p_beladiya committed Jan 25, 2021
1 parent f2a8f36 commit d3229fb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
21 changes: 10 additions & 11 deletions Basics/python_basics/17_inheritance/inheritace.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
class Father:
def __init__(self, name, lastname):
self.name = name
self.lastname = lastname
class Animal:
def __init__(self, living_place):
self.living_place = living_place

def printname(self):
print(self.name, self.lastname)
def printplace(self):
print(self.living_place)

class Son(Father):
def __init__(self, name, lastname):
super().__init__(name, lastname)
class Dog(Animal):
def __init__(self, living_place):
super().__init__(living_place)

x = Son("Darshan", "Beladiya")
x.printname()
x = Dog("zoo")
x.printplace()

10 changes: 5 additions & 5 deletions Basics/python_basics/17_inheritance/inheritance.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
## Exercise: Inheritance

1. create inheritance using father son relation on printname.
1. create inheritance using animal dog relation.


```
for example,
father and son both has name so create a method for printname by passing firstname and lastname
animal and dog both has same living_place so create a method for living_place
```

2. use super() constructor for calling parent constructor.

```
class father:
class animal:
#code
class son(father):
super()-it refers father class,now you can call father'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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
## Exercise: Multiple Inheritance

Real Life Example :
1. Create multiple inheritance in mario game
1. Create multiple inheritance on teacher,student and youtuber.


```
Q. if we have created Mario Game with only move module and now we wants to add jump as well as eat then what???
Q. if we have created teacher and now one student joins master degree with becoming teacher then what??
Ans : just make subclass from teacher so that student will become teacher
```

2. Now student is teacher as well as youtuber then what???


```
-just use multiple inheritance for these three relations
Ans : just make subclass from mario and add extra methods so that we will be having expanded class.
```


Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
class superMario():
def move(self):
print('I am moving')
class Teacher():
def teachers_action(self):
print('I can teach')


class jump():
def jump_above(self):
print('I just jumped')
class Engineer():
def Engineers_action(self):
print('I can code')

class mushroom():
def eat_mushroom(self):
print('I have become big now')
class Youtuber():
def youtubers_action(self):
print('I can code and teach')


class Mario(superMario, mushroom, jump):
class Person(Teacher, Engineer, Youtuber):
pass
play = Mario()
play.move()
play.eat_mushroom()
play.jump_above()
coder = Person()
coder.teachers_action()
coder.Engineers_action()
coder.youtubers_action()

0 comments on commit d3229fb

Please sign in to comment.