Skip to content

Commit

Permalink
Create inheritance_YahV1729.python
Browse files Browse the repository at this point in the history
this is a simple program to determine the concept of inheritance through python language.
  • Loading branch information
rvyash authored Oct 12, 2019
1 parent af95fad commit d590ead
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions inheritance_YahV1729.python
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# A Python program to demonstrate inheritance

# Base or Super class. Note object in bracket.
# (Generally, object is made ancestor of all classes)
# In Python 3.x "class Person" is
# equivalent to "class Person(object)"
class Person(object):

# Constructor
def __init__(self, name):
self.name = name

# To get name
def getName(self):
return self.name

# To check if this person is employee
def isEmployee(self):
return False


# Inherited or Sub class (Note Person in bracket)
class Employee(Person):

# Here we return true
def isEmployee(self):
return True

# Driver code
emp = Person("Geek1") # An Object of Person
print(emp.getName(), emp.isEmployee())

emp = Employee("Geek2") # An Object of Employee
print(emp.getName(), emp.isEmployee())

0 comments on commit d590ead

Please sign in to comment.