Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 209e9ab

Browse files
revised all concepts again
1 parent b2910c4 commit 209e9ab

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# # OOP REVISION
2+
# # OOP STANDS FOR OBJECT ORIENTED PROGRAMMING
3+
# # IT IS A PROGRAMMING PARADIGM BASED ON THE CONCEPT OF "OBJECTS
4+
# # ANYTHING THAT CAN BE REPRESENTED AS AN OBJECT CAN BE MANIPULATED USING OOP
5+
# # OOP IS USED TO SIMPLIFY THE COMPLEXITY OF PROGRAMMING BY BREAKING DOWN
6+
7+
# # CLASS AND OBJECTS
8+
# # CLASS IS A BLUEPRINT OR A TEMPLATE THAT DEFINES THE PROPERTIES AND BEHAVIOUR
9+
# # OF AN OBJECT
10+
11+
# class Dog:
12+
# def __init__(self,name,breed,age):
13+
# self.name = name
14+
# self.breed = breed
15+
# self.age = age
16+
17+
# def sound(self):
18+
# print("Woof")
19+
# def eat(self,meal):
20+
# print(f"{self.name} is eating {meal}")
21+
22+
# d1 = Dog("bella","germen","4")
23+
24+
# print(d1.name)
25+
# print(d1.breed)
26+
# print(d1.age)
27+
28+
# d1.sound()
29+
# d1.eat("Biscuit")
30+
31+
# print()
32+
33+
# d2 = Dog("max","bulldog","5")
34+
# print(d2.name)
35+
# print(d2.breed)
36+
# print(d2.age)
37+
# d2.sound()
38+
# d2.eat("meat")
39+
40+
41+
# # INHERITANCE
42+
# # IT IS A MECHANISM THAT ALLOWS ONE CLASS TO INHERIT THE PROPERTIES
43+
# # AND BEHAVIOR OF ANOTHER CLASS
44+
45+
# class Father:
46+
# def guide(self):
47+
# print("I will guide you")
48+
# def work(self):
49+
# print("I will work")
50+
# class Child(Father):
51+
# def play(self):
52+
# print("I will play")
53+
54+
# def eat(self):
55+
# print(" I am eating")
56+
57+
# c1 = Child()
58+
# c1.play()
59+
# c1.eat()
60+
# c1.guide()
61+
# c1.work()
62+
63+
# # MUltiple Inheritance
64+
# class Father:
65+
# def show_father_traits(self):
66+
# return "Father's traits"
67+
68+
# class Mother:
69+
# def show_mother_traits(self):
70+
# return "Mother's traits"
71+
72+
# class Child(Father, Mother):
73+
# def show_child_traits(self):
74+
# return "Child's traits"
75+
76+
# # Testing
77+
# child = Child()
78+
# print(child.show_father_traits()) # Output: Father's traits
79+
# print(child.show_mother_traits()) # Output: Mother's traits
80+
# print(child.show_child_traits()) # Output: Child's traits
81+
82+
# # Multilevel Inheritance
83+
# class Grandfather:
84+
# def show_grandfather_traits(self):
85+
# return "Grandfather's traits"
86+
87+
# class Father(Grandfather):
88+
# def show_father_traits(self):
89+
# return "Father's traits"
90+
91+
# class Child(Father):
92+
# def show_child_traits(self):
93+
# return "Child's traits"
94+
95+
# # Testing
96+
# child = Child()
97+
# print(child.show_grandfather_traits()) # Output: Grandfather's traits
98+
# print(child.show_father_traits()) # Output: Father's traits
99+
# print(child.show_child_traits()) # Output: Child's traits
100+
101+
102+
# # Hierarchical Inheritance
103+
# class Grandfather:
104+
# def show_grandfather_traits(self):
105+
# return "Grandfather's traits"
106+
107+
# class Father(Grandfather):
108+
# def show_father_traits(self):
109+
# return "Father's traits"
110+
111+
# class Mother(Grandfather):
112+
# def show_mother_traits(self):
113+
# return "Mother's traits"
114+
115+
# # Testing
116+
# father = Father()
117+
# mother = Mother()
118+
# print(father.show_grandfather_traits()) # Output: Grandfather's traits
119+
# print(father.show_father_traits()) # Output: Father's traits
120+
# print(mother.show_grandfather_traits()) # Output: Grandfather's traits
121+
# print(mother.show_mother_traits()) # Output: Mother's traits
122+
123+
# # HyBRID INHERITANCE
124+
125+
# class Grandfather:
126+
# def show_grandfather_traits(self):
127+
# return "Grandfather's traits"
128+
129+
# class Father(Grandfather):
130+
# def show_father_traits(self):
131+
# return "Father's traits"
132+
133+
# class Mother:
134+
# def show_mother_traits(self):
135+
# return "Mother's traits"
136+
137+
# class Child(Father, Mother):
138+
# def show_child_traits(self):
139+
# return "Child's traits"
140+
141+
# # Testing
142+
# child = Child()
143+
# print(child.show_grandfather_traits()) # Output: Grandfather's traits
144+
# print(child.show_father_traits()) # Output: Father's traits
145+
# print(child.show_mother_traits()) # Output: Mother's traits
146+
# print(child.show_child_traits()) # Output: Child's traits
147+
148+
149+
# ENCAPSULATION:
150+
151+
class Dog:
152+
def __init__(self,name,breed,age):
153+
self.__name = name
154+
self.__breed = breed
155+
self.__age = age
156+
157+
def __sound(self):
158+
print("Woof")
159+
def __eat(self,meal):
160+
print(f"{self.__name} is eating {meal}")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /