Posts

Showing posts with the label inheritance

Explain Inheritance in python.

Inheritance : Inheritance enables us to define a class that takes all the functionality from a parent class and allows us to add more. Classes can inherit from other classes. A class can inherit attributes and behavior methods from another class, called the superclass. A class which inherits from a superclass is called a subclass, also called heir class or child class. Superclasses are sometimes called ancestors as well. Syntax : class DerivedClass(BaseClass) :    body_of_derived_class A derived class inherits features from the base class, adding new features to it. This results in re-usability of code. If an attribute is not found in the class, the search continues to the base class. This repeats recursively if the base class is derived from other classes. Ex : class Polygon:    def __init__(self, no_of_sides):        self.n = no_of_sides       ...