![]() ![]() Here, we are using labrador (object of Dog) to access name and eat() of the Animal class. Notice the statements, labrador.name = "Rohu" In the above example, we have derived a subclass Dog from a superclass Animal. # access name attribute of superclass using self # attribute and method of the parent class Here, we are inheriting the sub_class class from the super_class class.Įxample 1: Python Inheritance class Animal: Here's the syntax of the inheritance in Python, # define a superclass ![]() The new class that is created is known as subclass (child or derived class) and the existing class from which the child class is derived is known as superclass (parent or base class). Inheritance allows us to create a new class from an existing class. Each course will earn you a downloadable course certificate.Like any other OOP languages, Python also supports the concept of class inheritance. Our premium courses offer a superior user experience with small, easy-to-digest lessons, progress tracking, quizzes to test your knowledge, and practice sessions.
0 Comments
Leave a Reply. |