-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17-Inheritance.py
92 lines (84 loc) · 2.25 KB
/
17-Inheritance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# --------------------------------------------------------------------------------------------------------------------------------------------
# Inheritance is an important aspects
# It provide code reuseability
# Concepts are Base class and derived class
# Derived class acquires properties from the base class
# Derived class----> Base class {One on One Inheritance}
# Multi level Inheritance [ ClassN-->Class2-->Class1]
# Base Class1 Base Class2 Base Class N
# | | |
# | | |
# ----Derived Class-----
# class Vehicle:
# def engine(self):
# print("I am from base class")
# class Car(Vehicle):
# def break_system(self):
# print("I am from derived class")
#
# # v = Vehicle()
# # v.engine()
# c = Car()
# c.break_system()
# c.engine()
#
# class Tree:
# def Root(self):
# print("It's base class ")
# class Mango(Tree):
# def leaf(self):
# print("It's derived class")
#
# # t = Tree ()
# # t.Root()
# m = Mango()
# m.Root()
# m.leaf()
# Multi level inheritance
class Vehicle:
def engine(self):
print("I am from base class")
class Car(Vehicle):
def break_system(self):
print("I am from derived class")
class Mini_Car(Car):
def mini_hand_break(self):
print("I am from CAR derived class")
# v = Vehicle()
# v.engine()
# c = Car()
# c.break_system()
# c.engine()
m = Mini_Car()
m.engine()
m.mini_hand_break()
m.break_system()
# # Multiple inheritance
# class Vehicle:
# def engine(self):
# print("I am from base class")
# class Car:
# def break_system(self):
# print("I am from derived class")
# class Mini_Car(Car,Vehicle):-------------------------> #This the diff of multi and multiple
# def mini_hand_break(self):
# print(" I am from CAR derived class")
#
# m = Mini_Car()
# m.engine()
# m.break_system()
# m.mini_hand_break()
#
# class Shoes:
# def Sports_Shoes(self):
# print("I am from base class")
# class Addids_Shoes(Shoes):
# def Running_shoe(self):
# print(" I am from derived class")
#
# # S = Shoes()
# # S.Sports_Shoes()
# # <It's my sample Ex>
# A = Addids_Shoes()
# A.Running_shoe()
# A.Sports_Shoes()