fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Meal {
  8.  
  9. public boolean isWarm() {
  10. return false;
  11. }
  12.  
  13. }
  14.  
  15. class Fish extends Meal {
  16.  
  17. }
  18.  
  19. class WarmMeal extends Meal {
  20. Meal meal;
  21.  
  22. public WarmMeal(Meal meal) {
  23. this.meal = meal;
  24. }
  25.  
  26. public boolean isWarm() {
  27. return true;
  28. }
  29.  
  30. public String toString() {
  31. return meal.toString();
  32. }
  33. }
  34.  
  35. class Microwave {
  36.  
  37. public static Meal warm(Meal meal)
  38. {
  39. System.out.println("Pogrzewam posiłek");
  40. return new WarmMeal(meal);
  41. }
  42.  
  43. }
  44.  
  45.  
  46. /* Name of the class has to be "Main" only if the class is public. */
  47. class Ideone
  48. {
  49. public static void main (String[] args) throws java.lang.Exception
  50. {
  51. Meal fish = new Fish();
  52. System.out.println("Potrawa gotowa do pieczenia: "+fish.toString());
  53. System.out.println("Czy ciepła?: "+fish.isWarm());
  54. fish = Microwave.warm(fish);
  55. System.out.println("Potrawa podgrzana: "+fish.toString());
  56. System.out.println("Czy ciepła?: "+fish.isWarm());
  57. }
  58. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Potrawa gotowa do pieczenia: Fish@14ae5a5
Czy ciepła?: false
Pogrzewam posiłek
Potrawa podgrzana: Fish@14ae5a5
Czy ciepła?: true