Interview Question

What is inheritance?

Inheritance lets subclasses reuse and specialize base-class behavior.

💡 Concept ✅ Quick Revision 🐍 Python

Answer

Inheritance lets a class derive attribute behavior from base classes. β€’ A subclass lists its bases in the class definition. β€’ Method resolution order controls attribute lookup across bases. β€’ Composition may be clearer when the relationship is not truly β€œis-a.”

💡 Simple Example

class Animal: def speak(self): return 'sound' class Dog(Animal): pass print(Dog().speak())

Output

sound

⚡ Quick Revision

Inheritance lets subclasses reuse and specialize base-class behavior.