Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
Overriding:
A method with same name, signature, arguments, return type defined in Super class and Sub class. Out of the two methods the subclass method is executed. This is achieved by declaring VIRTUAL the function Virtual.
Example:
class Parent{
virtual int child(){};
}
class Child: Parent {
int child(){};
}
Overloading:
This is basically overloading of a particular function achieved by varying the number/data type of arguments.
Example :
int area (int r) {};
int area(int a, int b) {};
overrinding requires same method signature (name name parameter) and same return type.
- Sam March 08, 2012super class having non-final instance methods that are directly accessible from the subclass are applicable for overriding.
While
Overloading occurs when the method names are same but different parameter(in order,type or number).