Next Index Previous

Python Examples

15. Python Class Inheritance example.

class Employee:
	id, name = '', ''
	
	def __init__(self,i,n):
		self.id = i
		self.name = n
		
	def display(self):
		print(self.id)
		print(self.name)
		
class Salary(Employee):
	basic = 0
	hra,ta,pf,ns = 0,0,0,0
	
	def sal(self):
		self.hra = (self.basic*30)/100
		self.ta = (self.basic*5)/100
		self.pf = (self.basic*12)/100
		self.ns = (self.basic+self.hra+self.ta)-self.pf
		
	def report(self):
		print(self.id)
		print(self.name)
		print(self.ns)
		
giri = Salary('101','Girish')
giri.basic = 25000
giri.sal()
giri.report()
Output :
101
Girish
30750.00


Father of Python Language

Guido-van-Rossum

Guido van Rossum

Born: January 31, 1956, Netherlands
Google+