CodesJava

Easy learning with example program codes

Python Inheritance


Python Inheritance:

Like Java and C++, Python is also based on OOPs Concept, i.e, Python is an object-oriented programming language which uses classes and objects for computations.

The property of acquiring all the properties and behaviors of the parent object by an object is termed as inheritance in OOPs. This is a unique feature in object oriented programming languages which facilitates reusability of the code of the parent class by the derived class.

Syntax 1:

class Derived_Class_Name (Base_Class_Name):

 <statement-1> 

    . 

    . 

    . 

    <statement-N> 

Syntax 2:

class Derived_Class_Name (modulename.Base_Class_Name):

<statement-1> 

    . 

    . 

    . 

    <statement-N>

 

Example:

class Employees(): 
 
   def Name(self): 
       print "Employee Name: Khush"
 
class salary(Employees):
   def Salary(self):
       print "Salary: 10000"
 
call = salary()
call.Name()
call.Salary()

Output:

Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki