Inheritance - Python

Re-using the properties of existing once are called inheritance and derivation , types
Simple inheritance
Multiple inheritance
Multilevel inheritance
Hierarchical inheritance
Hybrid inheritance

Syntax:

class DerivedClass(BaseClass1,basieclass2,…):
    body_of_derived_class

 

program on simple inheritace

class abc:
def get(self,x):
self.a=x
class xyz(abc):
def get1(self,x):
self.b=x
def put(self):
print("Sum of 2nos  ",self.a+self.b)
x=xyz()
x.get(4)
x.get1(9)
x.put()

 

Program to find the simple interest using multilevel inheritance
Program to find the simple interest using multiple inheritance
Find the net amount of a product using hierarchical inheritance
Fine the net salary of an employ using hybrid inheritance

 

Constructors in inheritance

Program to find the sum of 2nos using constructors in inheritance

class abc:
def __init__(self,x):
self.a=x
class xyz(abc):
def __init__(self,x,y):
abc.__init__(self,x)
# we can call the super class consturcor using super keyword
# super().__init__(x)
self.b=y
def put(self):
print("Sum of 2nos  ",self.a+self.b)
x=xyz(5,4)

x.put()

 

For
More Explanation
&
Online Classes

Contact Us:
+919885348743