fork(2) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone{
  6. public static void main(String[] args) {
  7. Potwor[] ptw = new Potwor[3];
  8. ptw[0] = new Wampir();
  9. ptw[1] = new Smok();
  10. ptw[2] = new Potwor();
  11. for (int x = 0; x < 3; x++) {
  12. if (ptw[x] instanceof Wampir{
  13. ptw[x].strasz(""+x);
  14. }else{
  15. ptw[x].strasz(x);
  16. }}
  17.  
  18. }
  19. }
  20.  
  21. class Potwor {
  22. boolean strasz(int z) { // pierwotna metoda
  23. System.out.println("auuuuuu");
  24. return true;
  25. }
  26. }
  27.  
  28. class Wampir extends Potwor { // przeciążona metoda
  29. boolean strasz(String b) {
  30. System.out.println("można gryza");
  31. return true;
  32. }
  33. }
  34.  
  35. class Smok extends Potwor {
  36. boolean strasz(int stopien) { // przesłonięta metoda
  37. System.out.println("zioń ogniem");
  38. return true;
  39. }
  40. }
Compilation error #stdin compilation error #stdout 0.06s 711168KB
stdin
Standard input is empty
compilation info
Main.java:12: error: ')' expected
    		if (ptw[x] instanceof Wampir{
    		                            ^
1 error
stdout
Standard output is empty