Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
29 views

Inheritance in Python:: Terminologies

Inheritance in Python allows the creation of new classes from existing classes. The new subclass inherits all non-private variables and methods from the parent class. This represents real-world relationships and provides code reusability without modifying existing classes. Inheritance is transitive, meaning subclasses of a child class will inherit from the grandparent class. There are two types: single inheritance where a child class inherits from one parent, and multiple inheritance where a class inherits from more than one base class.

Uploaded by

warriors
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Inheritance in Python:: Terminologies

Inheritance in Python allows the creation of new classes from existing classes. The new subclass inherits all non-private variables and methods from the parent class. This represents real-world relationships and provides code reusability without modifying existing classes. Inheritance is transitive, meaning subclasses of a child class will inherit from the grandparent class. There are two types: single inheritance where a child class inherits from one parent, and multiple inheritance where a class inherits from more than one base class.

Uploaded by

warriors
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

INHERITANCE IN PYTHON:

1. Inheritance is a key concept in Object-Oriented Programming.


2. Enables us to create a new class from an existing class.
3. The new class is a specialized version of the existing class and it inherits
all the non-private variables and methods of the existing class.
Its Benefits:
1) It represents real-world relationships well.
2) It provides reusability of a code. We don’t have to write the same code
again and again. Also, it allows us to add more features to a class
without modifying it.
3) It is transitive in nature, which means that if class B inherits from
another class A, then all the subclasses of B would automatically inherit
from class A.

Terminologies:
Superclass or parent class: the existing class.
Subclass or child class: the class inherits the superclass.

Syntax:
class ParentClass:
class ChildClass(ParentClass):

ex:

types :
1) single inheritance:
When a child class inherits from only one parent class.

Ex:

2) MULTIPLE INHERITANCE:
When a class is derived from more than one base class.
Syntax: Class Base1:
Body of the class
Class Base2:
Body of the class
Class Derived(Base1, Base2):
Body of the class
Ex:

You might also like