Skip to content

Commit d590ead

Browse files
authored
Create inheritance_YahV1729.python
this is a simple program to determine the concept of inheritance through python language.
1 parent af95fad commit d590ead

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

inheritance_YahV1729.python

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# A Python program to demonstrate inheritance
3+
4+
# Base or Super class. Note object in bracket.
5+
# (Generally, object is made ancestor of all classes)
6+
# In Python 3.x "class Person" is
7+
# equivalent to "class Person(object)"
8+
class Person(object):
9+
10+
# Constructor
11+
def __init__(self, name):
12+
self.name = name
13+
14+
# To get name
15+
def getName(self):
16+
return self.name
17+
18+
# To check if this person is employee
19+
def isEmployee(self):
20+
return False
21+
22+
23+
# Inherited or Sub class (Note Person in bracket)
24+
class Employee(Person):
25+
26+
# Here we return true
27+
def isEmployee(self):
28+
return True
29+
30+
# Driver code
31+
emp = Person("Geek1") # An Object of Person
32+
print(emp.getName(), emp.isEmployee())
33+
34+
emp = Employee("Geek2") # An Object of Employee
35+
print(emp.getName(), emp.isEmployee())

0 commit comments

Comments
 (0)