Guest User

Untitled

a guest
May 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. interface Runnable
  2. {
  3.     void run();
  4. }
  5.  
  6. class Animal implements Runnable
  7. {
  8.     public void run()
  9.     {
  10.         System.out.println("Animal.run()");
  11.     }
  12. }
  13.  
  14. class Person implements Runnable
  15. {
  16.     public void run()
  17.     {
  18.         System.out.println("Person.run()");
  19.     }
  20. }
  21.  
  22. class Other
  23. {
  24.     public void run()
  25.     {
  26.         System.out.println("A");
  27.     }
  28. }
  29.  
  30. public class Main
  31. {
  32.     static void runARunnable(Runnable r)
  33.     {
  34.         r.run();
  35.     }
  36.    
  37.     public static void main(String[] args)
  38.     {
  39.         Person p = new Person();
  40.         Animal a = new Animal();
  41.         Other  o = new Other();
  42.         runARunnable(p);
  43.         runARunnable(a);
  44.        
  45. //      Syntax Error
  46. //      runARunnable(o);       
  47.     }
  48. }
Add Comment
Please, Sign In to add comment