File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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())
You can’t perform that action at this time.
0 commit comments