Method Overriding is a technique that allows the invoking of functions from another class (base class) in the derived class. Creating a method in the derived class with the same signature as a method in the base class is called
Method Overriding.
In simple words, Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes. When a method in a subclass has the same name, same parameters or signature and the same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.
Example:
Output:
My new parent class.. !
My new child class.. !
In
Method Hiding, you can hide the implementation of the methods of a base class from the derived class using the
new keyword. Or in other words, in method hiding, you can redefine the method of the base class in the derived class by using the new keyword.
Example: