Ex. No.
8—- Creating Inheritance in Python
Inheritance
Inheritance allows a class to acquire the properties and methods of another class.
Aim:
To create inheritance using a base class and a derived class in Python.
Algorithm:
Step-1:Start the execution
Step-2:Define a base class
Step-3:Define a derived class that inherits the base class
Step-4:Define methods in both classes
Step-5:Create an object of the derived class
Step-6:Access base class and derived class methods using the object
Step-7:Display the output
Step-8:Stop the execution.
Program:
# Base class
class Person:
def show_name(self):
print("Name: Arun")
# Derived class
class Student(Person):
def show_course(self):
print("Course: BCom CA")
# Create object of derived class
s = Student()
# Access base class method
s.show_name()
# Access derived class method
s.show_course()
Output:
Name: Arun
Course: BCom CA
Result:
Inheritance was successfully created and base class methods were accessed