CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Python · 7 min · free

Inheritance and Method Overriding in Python

7 min4 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

Learn inheritance in Python: parent and child classes, method overriding, super() and __init__, and multilevel inheritance.

On screen in this lesson

Four words we need

Class: a design, like the plan of a phone
Object: a real thing made from the class
Attribute: data stored in an object, like name
Method: a function written inside a class

What is inheritance?

A child class gets everything a parent class has
Parent class is also called the base class
Child class is also called the derived class
Write the parent in brackets: class Bike(Vehicle):

How Python finds a method

Look in the object's own class first
Not found? Look in the parent class
Still not found? Go up to the grandparent
Nowhere at all? AttributeError

Kinds of inheritance

KindShapeExample
SingleA to BPhone, SmartPhone
MultilevelA to B to CPerson to Monitor
HierarchicalA to B and CVehicle: Bike, Car
MultipleA and B to Cclass C(A, B)

Quick recap

Child class gets the parent's attributes and methods
Overriding: the child writes a method with the same name
super() calls the parent's version of a method
Call super().__init__() so parent attributes are set
Multilevel: grandparent to parent to child

Quick answers

What is method overriding?

The child writes a method with the same name as the parent's, and the child's version wins.

Why call super().__init__()?

A child's own __init__ replaces the parent's, so without super the parent's attributes like name are not stored.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. A child gets features from the parents, like eyes or height. Can a class in Python get features from another class? Yes, it can. Today we will learn parent and child classes, super, method overriding, and multilevel inheritance.

First, four words we will use again and again. A class is a design, like the plan of a phone model. An object is a real thing made from that class, like the phone in your hand. An attribute is data kept inside an object, like a name or a price. A method is a function written inside a class, and it works on the object.

Inheritance means one class takes the attributes and methods of another class. The class that gives is the parent class. People also call it the base class. The class that receives is the child class, also called the derived class. In Python, we write the parent's name in round brackets after the child's name. Java uses the word extends for the same idea.

Here, Vehicle is the parent class with one method, start. The word self means the object that is using the method. Bike is the child, and Vehicle is in its brackets. The word pass means the child adds nothing new. We make a Bike object and call start. Bike has no start of its own, so it uses the parent's method, and prints Engine on.

A child can also add new methods of its own. A short method can sit on one line after the colon. Every phone can make a call. A smartphone is a phone, and it can also take a photo. So the SmartPhone object can call, from the parent, and click a photo, from itself. A plain Phone object cannot use photo, because parents never get the child's methods.

Sometimes the child needs the same method, but with different work. Overriding means the child writes a method with the same name as the parent's method. In our example, a normal ticket for a school fun fair costs one hundred rupees. A student ticket overrides fare and gives fifty. Ticket, with empty brackets, makes an object on the spot. So the first line prints one hundred, and the second prints fifty.

How does Python choose which fare to run? It looks in the object's own class first. If the method is not there, it looks in the parent class. If it is still not found, it goes one more step up. If the method is nowhere, Python stops with an attribute error. That is why the child's method wins when both have the same name.

Now a common trap. Dunder init, with two underscores on each side, runs automatically when an object is made. It sets up the attributes. Here, the letter n holds the name. Topper writes its own init, so it overrides the parent's init. The function vars shows every attribute inside an object. Look, only rank is there. The name was never stored, because the parent's init never ran.

The fix is super. Super, with round brackets, gives us the parent class, so we can call its methods. Inside Topper's init, we first call super, dot, init, and pass the name. The parent stores the name. Then the child adds its own new attribute, rank. Now both name and rank are inside the object. This is called extending init, because we keep the parent's work and add more.

Super works in any overridden method, not only init. A canteen bill gives a total of two hundred rupees. TaxBill overrides total, but it does not write the price again. It asks the parent for its total, using super, and adds thirty six rupees of tax. So it prints two hundred thirty six. If the parent's price changes later, the child is still correct.

Inheritance comes in a few common shapes. In single inheritance, one parent has one child, like Phone and SmartPhone. In multilevel inheritance, a child is also the parent of another class, like a family of grandparent, parent and child. In hierarchical inheritance, one parent has many children, like Bike and Car both coming from Vehicle. In multiple inheritance, one child has two parents, written as class C of A comma B.

Here is multilevel inheritance, in three levels. Person is the grandparent. Student is a child of Person. Monitor, the class monitor, is a child of Student. So a Monitor object can walk, even though walk is two levels up. The function isinstance asks, is this object a kind of that class? A monitor is a person, so it prints True.

Pause and predict before the answer appears. Student has no role method of its own. What does Student, dot, role print? It prints Person, because Python goes up to the parent. Monitor overrides role, so Monitor's own method wins, and it prints Monitor. The closest method always wins.

Let us use everything in a small school app. Every member of the school has a name and an identity card. Teacher inherits init from Member, so we do not write it again. Teacher overrides card, and uses super to get the plain card first. Then it adds the word Staff in front. So it prints Staff Kajal.

Let us revise what we learned today. A child class gets all the attributes and methods of its parent. Overriding means the child writes a method with the same name, and the child's version wins. Super lets the child call the parent's version of a method. In a child's init, call super's init, or the parent's attributes are never set. And multilevel inheritance goes from grandparent, to parent, to child.

Courses that teach this

CourseUnit
Programming All levels PythonObject-Oriented Programming
Programming All levels JavaObject-Oriented Foundations

Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.

Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →