-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path24. Inheritance.py
46 lines (36 loc) · 1.14 KB
/
24. 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
class Entry:
def __init__(self, roll_no, name):
self.roll_no= roll_no
self.name= name
def show(self):
print(f"Roll No.:- {self.roll_no} and Name {self.name}")
class Course(Entry):
# INHERITANCE
def show(self):
print(f"Roll No.:- {self.roll_no} and Name {self.name} has done BTech in Computer Science")
a=Entry(10, "Saurabh Singh Bhandari")
a.show()
b=Course(11, "Nittin")
b.show()
class Entry:
def __init__(self, roll_no, name):
self.roll_no= roll_no
self.name= name
def show(self):
print(f"Roll No.:- {self.roll_no} and Name {self.name}")
class Course(Entry):
# INHERITANCE
def show(self):
print(f"Roll No.:- {self.roll_no} and Name {self.name} has done BTech in Computer Science")
super().show()
# The super() keyword in Python is used to refer to the parent class
class Computer_lab(Entry):
def __init__(self, roll_no, name, language):
super().__init__(roll_no, name)
self.language= language
a=Entry(10, "Saurabh Singh Bhandari")
a.show()
b=Course(11, "Nittin")
b.show()
c=Computer_lab(23,"Chaya" , "Java")
print(c.language)