fork download
  1. public class Main {
  2. public static interface Hello {
  3. public void hello();
  4. }
  5.  
  6. public static class HelloWorld implements Hello{
  7. public void hello() {
  8. System.out.println("Hi!!!");
  9. }
  10.  
  11. public void goodbye() {
  12. System.out.println("Good bye!!!");
  13. }
  14. }
  15.  
  16. public static void main(String[] args) {
  17. HelloWorld hw = new HelloWorld();
  18. hw.hello();
  19. hw.goodbye();
  20. example(hw);
  21.  
  22. Hello h = new HelloWorld();
  23. h.hello();
  24. // h.goodbye(); エラー。呼び出せない
  25. // example(h); エラー。呼び出せない
  26. }
  27.  
  28. public static void example(HelloWorld hw){
  29. hw.goodbye();
  30. }
  31. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
Hi!!!
Good bye!!!
Good bye!!!
Hi!!!