Witajcie,
jak wykonuje się ten kod od momentu pętli `for` do końca? Nie rozumiem co następuje po czym.
Wynik wykonania to:
można gryza?
zioń ogniem
ałuuu
public class PotworTester (
public static void main (String [] args) {
Potwor [] ptw = new Potwor [3];
ptw [0] = new Wampir();
ptw [1] = new Smok();
ptw [2] = new Potwor();
for (int x = 0, x<3; x++)
ptw[x].strasz[x];
}
}
}
class Potwor {
boolean strasz (int d) {
System.out.prinln ("ałuuu");
return true;
}
class Wampir extends Potwor {
boolean strasz (int x) {
System.out.println ("można gryza?");
return false;
}
class Smok extends Potwor {
boolean strasz (int stopien) {
System.out.prinln ("zioń ogniem");
return true;
}
}