You are on page 1of 5

Name :- Madhura Kank

Roll no :- 23
Practical 15

a)
# Python example to show the working of multiple inheritance
class Base1(object):
def __init__(self):
self.str1 = "Book1"
print("Base1")

class Base2(object):
def __init__(self):
self.str2 = "Book2"
print("Base2")

class Derived(Base1, Base2):


def __init__(self):
# Calling constructors of Base1and Base2 classes
Base1.__init__(self)
Base2.__init__(self)
print("Derived")

def printStrs(self):
print(self.str1, self.str2)

ob = Derived()
ob.printStrs()
2)
class Employee:
'Common base class for all employees'

def __init__(self):
self.name = ""
self.salary = 0.0
self.department= ""

def readEmployee(self):
self.name=input("Enter Name")
self.salary=float(input("Enter salary"))
self.department=input("Enter department")

def displayEmployee(self):
print ("Name : ", self.name, ", Salary: ", self.salary, "Department:",
self.department)
"This would create first object of Employee class"
emp1 = Employee()
"This would create second object of Employee class"
emp2 = Employee()
emp1.readEmployee()
emp2.readEmployee()
emp1.displayEmployee()
emp2.displayEmployee()

3) class Student:
def __init__(self):
self.name = input("Enter your name:")
self.cname = input("Enter your college name:")
self.roll = int(input("Enter your roll number:"))
class Test(Student):
def display(self):
print("============ Student info is ==========")
print("Name is : ", self.name)
print("College Name is:", self.cname)
print("Roll number is:", self.roll)
obj = Test()
obj.display()

4) #definition of the class starts here


class Person:
#defining constructor
def __init__(self, personName, personAge):
self.name = personName
self.age = personAge

#defining class methods


def showName(self):
print(self.name)

def showAge(self):
print(self.age)

#end of class definition

# defining another class


class Student: # Person is the
def __init__(self, studentId):
self.studentId = studentId

def getId(self):
return self.studentId

class Resident(Person, Student): # extends both Person and Student class


def __init__(self, name, age, id):
Person.__init__(self, name, age)
Student.__init__(self, id)

# Create an object of the subclass


resident1 = Resident('Jivan', 30, '102')
resident1.showName()
print(resident1.getId())
resident1.showAge()

You might also like