Overload principles:
- the method name must remain the same
- any access modifier is accapted, but just changing it is not enough for legal overloading
- any exception is accepted but changing it is not enough
- return type must be the same, changing it breaks oveloading and compilation fail due to ‘Duplicate method’
- with 2 method implementations: in subclass and in superclass, different return type is allowed (Super->Sub)
- in same one class: not allowed, changing return type super->sub
-
- return types: primitive type and wrapper object are not enough to overload but in properly overloaded method
- w przeladowanej na przestrzeni dwoch klas metodzie suber/sub w returnie jest ok
public abstract class Main {
public Main operate() {
return null;
}
}
class Klaska extends Main{
public Klaska operate(int i) {
return null;
}
}
Override principles:
- return type the same or subtype
- access modifier wider
- exception the same or subtype
- same name and sygnature
Hide principles:
- apply only to static methods
- are not polymorphic, you always call the reference type method
- should not be called on instances