I have a function in my superclass (Speler) that is called kiesKaart:
public Kaart kiesKaart(int spelerIndex){...}
In my subclass function, I have the same function with an other parameter that overrides (i do have @Override before it, changing this to @Override() does not help…) the super function:
public int kiesKaart(Kaart lak){...}
In my main I have an array of Spelers, where only the first is an Speler and the others are AiSpelers (this is the name of the subclass):
spelerArr[0] = new Speler(hand[0]);
for (int i=1;i<AANTALSPELERS;i++) {
spelerArr[i] = new AiSpeler(hand[i]);
}
Later on in my code I address spelerArr[i].kiesKaart, so now I want the code to address the correct instance of kiesKaart.
How can I do this?
Using
@Overridewill do nothing here because the two methods are different. The first one returns typeKaartgiven anint, and the second returns typeintgiven aKaart.In other words, to make sure you are calling the right method, you need to make sure you send the right parameter (
intfor the first,Kaartfor the second).