Pergunta de entrevista da empresa Cognizant

Difference between Method Overloading and Method Overriding

Resposta da entrevista

Sigiloso

24 de jan. de 2021

Method Overloading is a Compile time polymorphism. In method overloading, more than one method shares the same method name with different signature in the class. In method overloading, return type can or can not be be same, but we must have to change the parameter because in java, we can not achieve the method overloading by changing only the return type of the method. Method Overriding is a Run time polymorphism. In method overriding, derived class provides the specific implementation of the method that is already provided by the base class or parent class. In method overriding, return type must be same or co-variant (return type may vary in same direction as the derived class).