Inheritance in Python

 

Concept


Inheritance is the ability of any class to extract and use features of other classes. It is the process by which new classes called the derived classes are created from existing classes called Base classes.



Code Example


Example 1:

class Human:

    def __init__(self, z):
        self.address = z

    def print_address(self):
        print(self.address)

class Student(Human):    

    def __init__(self, x, y, z):
        Human.__init__(self, z)
        self.name = x
        self.roll = y

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

    def print_roll(self):
        print(self.roll)

# Object Creation
obj = Student("Kuntal", 10, "Kolkata")
print(type(obj))
obj.print_name()
obj.print_roll()
obj.print_address()


Quiz Level 1

Quiz Level 2


Request Me


Click Here For More






Comments

Popular posts from this blog

How To Create .ENV File in Python

Create a Large file for Test Data Processing using Python

How to solve the Liner Equation using Python