Professional Documents
Culture Documents
PPS U5 Module2 (A)
PPS U5 Module2 (A)
PPS U5 Module2 (A)
● You declare other class methods like normal functions with the exception
that the first argument to each method is self.
class Student:
def display(self):
print(self.name)
print(self.age)
Output :
Soham
obj = Student("Soham", 20)
20
obj.display()
class employee:
def __init__(self, name,age,salary,address):
self.name = name
obj = employee("Soham", 20, 30000,'Nashik')
self.age = age
obj.display()
self.salary = salary
self.address = address
Output :
Soham
def display(self): 20
print(self.name) 30000
Nashik
print(self.age)
print(self.salary)
print(self.address)
Inheritance : Inheritance is the capability of one class to derive or inherit the
properties from another class.
The child class acquires the properties and can access all the data members and
functions defined in the parent class. A child class can also provide its specific
implementation to the functions of the parent class.
class Parent():
def first(self):
print('first function')
Kids singing
obj = kids() Father Speaking
obj.sing()
obj.speak()
class Addition:
def add(self): obj = Show()
a=10 obj.display()
b=20 obj.add()
sum=a+b
print("Sum=",sum) Output :
This is Addition
#child class show inherits the base class Addition ('Sum=', 30)
class Show(Addition):
def display(self):
print("This is Addition")