Overriding
TLDR: Overriding is a programming concept where a subclass provides a specific implementation of a method already defined in its superclass. This feature is essential in object-oriented programming, enabling dynamic method dispatch (dynamic dispatch) and runtime polymorphism. By overriding methods, subclasses can tailor the behavior inherited from the parent class to suit their unique requirements while adhering to the same method signature.
https://en.wikipedia.org/wiki/Method_overriding
In Java and CPP, overriding requires that the method in the subclass have the same method name, parameters, and return type as the method in the superclass. For example, if a superclass `Animal` defines a method `move()`, a subclass `Bird` might override it to implement flying behavior instead of walking. The `Java @Override` annotation in Java helps ensure that the overridden method matches the parent class definition, reducing errors during compilation.
https://docs.oracle.com/javase/tutorial/java/IandI/override.html
Overriding is central to achieving dynamic method binding, where the method that gets executed is determined at runtime based on the object type. This contrasts with overloading, which occurs at compile time. By allowing specific behavior for subclasses while maintaining a common interface, overriding supports extensibility and flexibility in program design, making it a cornerstone of scalable object-oriented programming.
https://docs.oracle.com/javase/specs/jls/se20/html/jls-8.html