I was trying to answer another SO question which led me to me asking my own one. I did some research but could not find any information on the above topic.
I have an abstract class Character
which has 1 abstract method defined below with varargs parameter
public abstract class Character {
public abstract void doSomething(int... values);
}
I was under the impression that any class that extends this class could override this method with any number of parameters.
// 1st example
public class Player extends Character {
@Override
public void doSomething(int x, int y) { // Two params - do something }
}
// 2nd example
public class NPC extends Character {
@Override
public void doSomething() { // No params - do something }
}
But both the above examples resulted in a compile time error. I wanted to know what am I missing here? Is the above mentioned scenario even possible?
Any help is appreciated.