Skip to content

Commit fa09c7e

Browse files
2 parents 682bf59 + c504905 commit fa09c7e

File tree

65 files changed

+15628
-760
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+15628
-760
lines changed
Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "457fafa0",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"# inheritance in python\n",
11+
"\n",
12+
"# type of inheritance\n",
13+
"# single inheritance\n",
14+
"# multiple inheritance\n",
15+
"# multilevel inheritance\n",
16+
"# hierarchical inheritance\n",
17+
"# hybrid inheritance\n",
18+
"\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 3,
24+
"id": "81d6b67b",
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"# single inheritance\n",
29+
"class Customer:\n",
30+
" def CustomerDetails(self):\n",
31+
" print(\"Customer Details\")\n",
32+
" print(\"Name: John Doe\")\n",
33+
" print(\"Age: 30\")\n",
34+
" print(\"Address: 123 Main St\")\n",
35+
" \n",
36+
" \n",
37+
"class Product(Customer):\n",
38+
" def ProductDetails(self):\n",
39+
" print(\"Product Details\")\n",
40+
" print(\"Product Name: Laptop\")\n",
41+
" print(\"Price: $1000\")\n",
42+
" print(\"Quantity: 5\") "
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": 4,
48+
"id": "59551051",
49+
"metadata": {},
50+
"outputs": [
51+
{
52+
"name": "stdout",
53+
"output_type": "stream",
54+
"text": [
55+
"Customer Details\n",
56+
"Name: John Doe\n",
57+
"Age: 30\n",
58+
"Address: 123 Main St\n",
59+
"Product Details\n",
60+
"Product Name: Laptop\n",
61+
"Price: $1000\n",
62+
"Quantity: 5\n"
63+
]
64+
}
65+
],
66+
"source": [
67+
"# create an instance of Product\n",
68+
"product = Product()\n",
69+
"# call methods from both Customer and Product classes\n",
70+
"product.CustomerDetails()\n",
71+
"product.ProductDetails()"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": 11,
77+
"id": "d4f94634",
78+
"metadata": {},
79+
"outputs": [],
80+
"source": [
81+
"# multiple inheritance\n",
82+
"class Course:\n",
83+
" def CourseDetails(self):\n",
84+
" print(\"Course Details\")\n",
85+
" print(\"Course Name: Python Programming\")\n",
86+
" print(\"Duration: 3 months\")\n",
87+
" print(\"Instructor: Jane Smith\")\n",
88+
"class Student:\n",
89+
" def StudentDetails(self):\n",
90+
" print(\"Student Details\")\n",
91+
" print(\"Name: Alice Johnson\")\n",
92+
" print(\"Age: 25\")\n",
93+
" print(\"Major: Computer Science\")\n",
94+
"class Enrollment(Course, Student):\n",
95+
" def EnrollmentDetails(self):\n",
96+
" print(\"Enrollment Details\")\n",
97+
" print(\"Enrollment ID: 12345\")\n",
98+
" print(\"Status: Active\")"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 12,
104+
"id": "7c68348a",
105+
"metadata": {},
106+
"outputs": [
107+
{
108+
"name": "stdout",
109+
"output_type": "stream",
110+
"text": [
111+
"Course Details\n",
112+
"Course Name: Python Programming\n",
113+
"Duration: 3 months\n",
114+
"Instructor: Jane Smith\n",
115+
"Student Details\n",
116+
"Name: Alice Johnson\n",
117+
"Age: 25\n",
118+
"Major: Computer Science\n",
119+
"Enrollment Details\n",
120+
"Enrollment ID: 12345\n",
121+
"Status: Active\n"
122+
]
123+
}
124+
],
125+
"source": [
126+
"# create an instance of Enrollment\n",
127+
"enrollment = Enrollment()\n",
128+
"# call methods from both Course and Student classes\n",
129+
"enrollment.CourseDetails()\n",
130+
"enrollment.StudentDetails()\n",
131+
"enrollment.EnrollmentDetails()"
132+
]
133+
},
134+
{
135+
"cell_type": "code",
136+
"execution_count": 7,
137+
"id": "a5b826c0",
138+
"metadata": {},
139+
"outputs": [],
140+
"source": [
141+
"# multilavel inheritance\n",
142+
"class Credicard:\n",
143+
" def CreditCardDetails(self):\n",
144+
" print(\"Credit Card Details\")\n",
145+
" print(\"Card Number: 1234-5678-9012-3456\")\n",
146+
" print(\"Expiry Date: 12/25\")\n",
147+
"class client(Credicard):\n",
148+
" def ClientDetails(self):\n",
149+
" print(\"Client Details\")\n",
150+
" print(\"Name: Jane Smith\")\n",
151+
" print(\"Age: 28\")\n",
152+
"class bank(client):\n",
153+
" def BankDetails(self):\n",
154+
" print(\"Bank Details\")\n",
155+
" print(\"Bank Name: ABC Bank\")\n",
156+
" print(\"Account Number: 9876543210\")"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": 8,
162+
"id": "79232e04",
163+
"metadata": {},
164+
"outputs": [
165+
{
166+
"name": "stdout",
167+
"output_type": "stream",
168+
"text": [
169+
"Credit Card Details\n",
170+
"Card Number: 1234-5678-9012-3456\n",
171+
"Expiry Date: 12/25\n",
172+
"Client Details\n",
173+
"Name: Jane Smith\n",
174+
"Age: 28\n",
175+
"Bank Details\n",
176+
"Bank Name: ABC Bank\n",
177+
"Account Number: 9876543210\n"
178+
]
179+
}
180+
],
181+
"source": [
182+
"bank_instance = bank()\n",
183+
"bank_instance.CreditCardDetails()\n",
184+
"bank_instance.ClientDetails()\n",
185+
"bank_instance.BankDetails()"
186+
]
187+
},
188+
{
189+
"cell_type": "code",
190+
"execution_count": 9,
191+
"id": "8fbce7b5",
192+
"metadata": {},
193+
"outputs": [
194+
{
195+
"name": "stdout",
196+
"output_type": "stream",
197+
"text": [
198+
"Vehicle Details\n",
199+
"Type: Car\n",
200+
"Model: Toyota\n",
201+
"Car Details\n",
202+
"Color: Red\n",
203+
"Year: 2020\n",
204+
"Vehicle Details\n",
205+
"Type: Car\n",
206+
"Model: Toyota\n",
207+
"Bike Details\n",
208+
"Color: Blue\n",
209+
"Year: 2019\n"
210+
]
211+
}
212+
],
213+
"source": [
214+
"# hierarchical inheritance\n",
215+
"class Vehicle:\n",
216+
" def VehicleDetails(self):\n",
217+
" print(\"Vehicle Details\")\n",
218+
" print(\"Type: Car\")\n",
219+
" print(\"Model: Toyota\")\n",
220+
"class Car(Vehicle):\n",
221+
" def CarDetails(self):\n",
222+
" print(\"Car Details\")\n",
223+
" print(\"Color: Red\")\n",
224+
" print(\"Year: 2020\")\n",
225+
"class Bike(Vehicle):\n",
226+
" def BikeDetails(self):\n",
227+
" print(\"Bike Details\")\n",
228+
" print(\"Color: Blue\")\n",
229+
" print(\"Year: 2019\")\n",
230+
"car_instance = Car()\n",
231+
"car_instance.VehicleDetails()\n",
232+
"car_instance.CarDetails()\n",
233+
"bike_instance = Bike()\n",
234+
"bike_instance.VehicleDetails()\n",
235+
"bike_instance.BikeDetails()"
236+
]
237+
},
238+
{
239+
"cell_type": "code",
240+
"execution_count": 13,
241+
"id": "b11224f9",
242+
"metadata": {},
243+
"outputs": [],
244+
"source": [
245+
"# hybrid inheritance\n",
246+
"class Books:\n",
247+
" def BookDetails(self):\n",
248+
" print(\"Book Details\")\n",
249+
" print(\"Title: Python Programming\")\n",
250+
" print(\"Author: John Smith\")\n",
251+
"class Magazine(Books):\n",
252+
" def MagazineDetails(self):\n",
253+
" print(\"Magazine Details\")\n",
254+
" print(\"Title: Tech Monthly\")\n",
255+
" print(\"Issue: January 2023\")\n",
256+
"class Newspaper(Books):\n",
257+
" def NewspaperDetails(self):\n",
258+
" print(\"Newspaper Details\")\n",
259+
" print(\"Title: Daily News\")\n",
260+
" print(\"Date: 01/01/2023\")\n",
261+
"class Library(Magazine, Newspaper):\n",
262+
" def LibraryDetails(self):\n",
263+
" print(\"Library Details\")\n",
264+
" print(\"Location: City Center\")\n",
265+
" print(\"Opening Hours: 9 AM - 5 PM\")"
266+
]
267+
},
268+
{
269+
"cell_type": "code",
270+
"execution_count": 14,
271+
"id": "f90ceb21",
272+
"metadata": {},
273+
"outputs": [
274+
{
275+
"name": "stdout",
276+
"output_type": "stream",
277+
"text": [
278+
"Book Details\n",
279+
"Title: Python Programming\n",
280+
"Author: John Smith\n",
281+
"Magazine Details\n",
282+
"Title: Tech Monthly\n",
283+
"Issue: January 2023\n",
284+
"Newspaper Details\n",
285+
"Title: Daily News\n",
286+
"Date: 01/01/2023\n"
287+
]
288+
}
289+
],
290+
"source": [
291+
"Library_instance = Library()\n",
292+
"Library_instance.BookDetails()\n",
293+
"Library_instance.MagazineDetails()\n",
294+
"Library_instance.NewspaperDetails()"
295+
]
296+
}
297+
],
298+
"metadata": {
299+
"kernelspec": {
300+
"display_name": "Python 3",
301+
"language": "python",
302+
"name": "python3"
303+
},
304+
"language_info": {
305+
"codemirror_mode": {
306+
"name": "ipython",
307+
"version": 3
308+
},
309+
"file_extension": ".py",
310+
"mimetype": "text/x-python",
311+
"name": "python",
312+
"nbconvert_exporter": "python",
313+
"pygments_lexer": "ipython3",
314+
"version": "3.13.5"
315+
}
316+
},
317+
"nbformat": 4,
318+
"nbformat_minor": 5
319+
}

0 commit comments

Comments
 (0)