fork 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. ptw[x].strasz(x);
  13. }
  14. }
  15. }
  16.  
  17. class Potwor {
  18. boolean strasz(int z) { // pierwotna metoda
  19. System.out.println("auuuuuu");
  20. return true;
  21. }
  22. }
  23.  
  24. class Wampir extends Potwor { // przeciążona metoda
  25. @Override
  26. boolean strasz(String b) {
  27. System.out.println("można gryza");
  28. return true;
  29. }
  30. }
  31.  
  32. class Smok extends Potwor {
  33. @Override
  34. boolean strasz(int stopien) { // przesłonięta metoda
  35. System.out.println("zioń ogniem");
  36. return true;
  37. }
  38. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:25: error: method does not override or implement a method from a supertype
    @Override
    ^
1 error
stdout
Standard output is empty