Overriding:
- Method overriding is a mechanism in which a subclass inherits the methods of the superclass and sometimes the subclass modifies the implementation of a method defined in the superclass.
- That means if subclass (Derived class) has the same method as declared in the parent class (base class).
- Method overriding is used for runtime polymorphism.
Rules for Java Method Overriding:
- The method must have the same name as in the parent class
- The method must have the same parameter as in the parent class.
- There must be inherited.
- A static method cannot be overridden. It can be proved by runtime polymorphism.
Syntax:
Example program:
Method overloading:
- Overloading is a mechanism in which we can use many methods having the same function name but can pass the different numbers of parameters or different types of parameters.
- In python, doest not call the data types at function definition.
- So python does not support method overloading.
No comments:
Post a Comment