Here's an example of method overriding in Python 3:
Here's an example of inheritance in Python 3: python 3 deep dive part 4 oop
Here's an example of encapsulation in Python 3: Here's an example of method overriding in Python
print(my_car.make) # Output: Toyota my_car.honk() # Output: Honk honk! Inheritance is a fundamental concept in OOP that allows one class to inherit the attributes and methods of another class. The class that is being inherited from is called the parent or superclass, and the class that is doing the inheriting is called the child or subclass. def area(self): return self
def area(self): return self.width ** 2 In this example, the Square class overrides the area method of the Rectangle class. Encapsulation is the concept of hiding the internal details of an object from the outside world and only exposing a public interface through which other objects can interact with it.
def honk(self): print("Honk honk!") In this example, Car is a class that has three attributes: make , model , and year . The __init__ method is a special method that is called when an object is created from the class. It initializes the attributes of the class.