Skip to content

Commit f5a1166

Browse files
author
Karandeep Grover
committed
Merge branch 'exercise_16_26' of github.com:beladiyadarshan/py into exercise_16_26
2 parents fb9940b + 253f1c6 commit f5a1166

File tree

4 files changed

+40
-33
lines changed

4 files changed

+40
-33
lines changed
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
class Father:
2-
def __init__(self, name, lastname):
3-
self.name = name
4-
self.lastname = lastname
1+
class Animal:
2+
def __init__(self, living_place):
3+
self.living_place = living_place
54

6-
def printname(self):
7-
print(self.name, self.lastname)
5+
def printplace(self):
6+
print(self.living_place)
87

9-
class Son(Father):
10-
def __init__(self, name, lastname):
11-
super().__init__(name, lastname)
8+
class Dog(Animal):
9+
def __init__(self, living_place):
10+
super().__init__(living_place)
1211

13-
x = Son("Darshan", "Beladiya")
14-
x.printname()
12+
x = Dog("zoo")
13+
x.printplace()
1514

Basics/Hindi/17_inheritance/inheritance.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
## Exercise: Inheritance
22

3-
1. create inheritance using father son relation on printname.
3+
1. create inheritance using animal dog relation.
44

55

66
```
77
for example,
8-
father and son both has name so create a method for printname by passing firstname and lastname
8+
animal and dog both has same living_place so create a method for living_place
99
```
1010

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

1313
```
14-
class father:
14+
class animal:
1515
#code
1616
17-
class son(father):
18-
super()-it refers father class,now you can call father's methods.
17+
class dog(animal):
18+
super()-it refers animal class,now you can call animal's methods.
1919
```
2020

2121
[Solution](https://github.com/codebasics/py/blob/master/Basics/python_basics/17_inheritance/17_inheritance.py)

Basics/Hindi/18_multiple_inheritance/multiple_inheritance.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
## Exercise: Multiple Inheritance
22

33
Real Life Example :
4-
1. Create multiple inheritance in mario game
4+
1. Create multiple inheritance on teacher,student and youtuber.
55

66

77
```
8-
Q. if we have created Mario Game with only move module and now we wants to add jump as well as eat then what???
8+
Q. if we have created teacher and now one student joins master degree with becoming teacher then what??
9+
10+
Ans : just make subclass from teacher so that student will become teacher
11+
```
12+
13+
2. Now student is teacher as well as youtuber then what???
14+
15+
16+
```
17+
-just use multiple inheritance for these three relations
918
10-
Ans : just make subclass from mario and add extra methods so that we will be having expanded class.
1119
```
1220

1321

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
class superMario():
2-
def move(self):
3-
print('I am moving')
1+
class Teacher():
2+
def teachers_action(self):
3+
print('I can teach')
44

55

6-
class jump():
7-
def jump_above(self):
8-
print('I just jumped')
6+
class Engineer():
7+
def Engineers_action(self):
8+
print('I can code')
99

10-
class mushroom():
11-
def eat_mushroom(self):
12-
print('I have become big now')
10+
class Youtuber():
11+
def youtubers_action(self):
12+
print('I can code and teach')
1313

1414

15-
class Mario(superMario, mushroom, jump):
15+
class Person(Teacher, Engineer, Youtuber):
1616
pass
17-
play = Mario()
18-
play.move()
19-
play.eat_mushroom()
20-
play.jump_above()
17+
coder = Person()
18+
coder.teachers_action()
19+
coder.Engineers_action()
20+
coder.youtubers_action()

0 commit comments

Comments
 (0)