Method Overloading and Overriding Flashcards
What is the other name for method overloading?
Static Polymorphism
How can you implement method overloading?
Implemented by having multiple methods with the same name in a class but with different arguments. Methods can have different number of parameters, different data type of parameters, different sequence of data type of parameters.
Why can’t the return type be different with method overloading?
This will lead to ambiguous behaviour.
How do we implement method overriding?
To override a method, we just provide a different implementation of a method with the same name in the subclass.
Are we allowed to override a static method in java?
Java does not allow overriding a static method. If you create a static method with the same name in a subclass, then it is a new method.