Module 5: Introduction to Object-Oriented Programming (OOP)
Simple Inheritance (Brief Overview)
Inheritance is a way to form new classes using classes that have already been defined. The new classes, known as derived classes or child classes, inherit attributes and methods of the parent (or base/superclass) classes. This promotes code reuse. Example (very basic):
class Animal: def speak(self): print("Animal speaks") class Cat(Animal): # Cat inherits from Animal def meow(self): print("Meow") my_cat = Cat() my_cat.speak() # Inherited from Animal: Output: Animal speaks my_cat.meow() # Output: Meow
This module focuses on understanding the basics of classes and objects rather than deep inheritance concepts.