0% found this document useful (0 votes)
67 views

Python Exp14,15,16

The document discusses Python classes and inheritance. It defines a Degree class with subclasses Undergraduate and Postgraduate. An object of each class is created and the getDegree method is called. It also implements multiple inheritance by defining classes Drive and Fly that are inherited by the Both class.

Uploaded by

HARSH MAGHNANI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Python Exp14,15,16

The document discusses Python classes and inheritance. It defines a Degree class with subclasses Undergraduate and Postgraduate. An object of each class is created and the getDegree method is called. It also implements multiple inheritance by defining classes Drive and Fly that are inherited by the Both class.

Uploaded by

HARSH MAGHNANI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Python Exp 14

14.1)

14.2)

14.3) Write a Python program to create a class 'Degree' having a method 'getDegree' that prints
"I got a degree". It has two subclasses namely 'Undergraduate' and 'Postgraduate' each having
a method with the same name that prints "I am an Undergraduate" and "I am a Postgraduate"
respectively. Call the method by creating an object of each of the three classes.

details.py:-
import socket
import datetime
def details():
print("Developed by CO6I_B_15");
print("Your Computer Name is: " + socket.gethostname());
print("Your Computer IP Address is: " + socket.gethostbyname(socket.gethostname()));
print("Time now is: " , datetime.datetime.now());

14.3)
import details

class Degree:

def getDegree(self):

print("I got a degree")


class UnderGraduate(Degree):

def detail(self):

print("I am an UnderGraduate")

class PostGraduate(Degree):

def detail(self):

print("I am an PostGraduate")

ob1 = Degree()

ob2 = UnderGraduate()

ob3 = PostGraduate()

ob1.getDegree()

ob2.detail()

ob3.detail()

details.details()

Output:
Python Exp 15

15.1)

15.2)

15.3) Write a Python program to implement multiple inheritance.

import socket

import datetime

class Drive:

def drive():

print('"Class Drive method drive():" Driving a car')

class Fly:

def fly():

print('"Class Fly method fly():" Flying a plane')

class Both(Drive,Fly):

print("This class inheriting details from Drive and Fly")

ob = Both

ob.drive()

ob.fly()

import details
details.details()

Output:-

Details.py:-

import socket
import datetime
def details():
print("Developed by CO6I_B_15");
print("Your Computer Name is: " + socket.gethostname());
print("Your Computer IP Address is: " + socket.gethostbyname(socket.gethostname()));
print("Time now is: " , datetime.datetime.now());
Python Exp 16

16.1)

16.2)

You might also like