Middle
If a method takes three parameters and you need to pass a fourth — should you overload or override the method?
sobes.tech AI
Answer from AI
If a method takes three parameters and you need to pass a fourth, the correct approach is to overload the method, that is, create a new version of the method with a different set of parameters. Overriding is replacing the implementation of a method in a subclass, but the method signature usually does not change.
Example in Java:
class Example {
void method(int a, int b, int c) {
// implementation
}
void method(int a, int b, int c, int d) {
// new implementation with 4 parameters
}
}