-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritence.py
56 lines (44 loc) · 1.34 KB
/
inheritence.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
45
46
47
48
49
50
51
52
53
54
55
56
# Inheritance concept
# Way of forming new classes using classes that are already defined
# lets create a base class
class Animal():
def __init__(self):
print ("Animal Created")
def who_am_i(self):
print ("i am an animal")
def eat(self):
print ("i am eating")
myanimal=Animal()
myanimal.who_am_i()
myanimal.eat()
myanimal
# lets create a derived class where we will be inheriting some of the features from the base class animal
# class Dog(Animal):
# def __init__(self):
# Animal.__init__(self)
# print ("Dog Created")
# # overriding eat method of Animal Class
# def eat(self):
# print ("I am a dog eating")
# def bark(self):
# print ("i am barking")
# mydog=Dog()
# mydog
# mydog.bark()
# mydog.who_am_i()
# mydog.eat()
class Employee():
empcount=0
def __init__(self,name,salary):
self.name=name
self.salary=salary
Employee.empcount=Employee.empcount+ 1
def displayEmployeeInfo(self):
print ("Employee Name",self.name,"Employee Salary",self.salary)
def employee_count(self):
print ("Employee Count",Employee.empcount)
emp_1=Employee("Bhawesh",2000)
emp_1.employee_count()
emp_2=Employee("Saumya",5000)
emp_2.employee_count()
emp_1.employee_count()