Guest User

Untitled

a guest
Mar 6th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1.  
  2. public class Parent {
  3.     public static void main(String[] m) {
  4.         Parent childAsParent = new Child();
  5.        
  6.         System.out.println("Calling static method with declared Parent of type Child.");
  7.         Binder.StaticMethod(childAsParent);
  8.         new Binder().InstanceMethod(childAsParent);
  9.     }
  10. }
  11.  
  12. class Child extends Parent {
  13.    
  14. }
  15.  
  16. class Binder {
  17.     public static void StaticMethod(Child d)
  18.     {
  19.         System.out.println("StaticMethod(Child d)");
  20.     }
  21.     public static void StaticMethod(Parent h)
  22.     {
  23.         System.out.println("StaticMethod(Parent h)");
  24.     }
  25.    
  26.     public void InstanceMethod(Child d)
  27.     {
  28.         System.out.println("InstanceMethod(Child d)");
  29.     }
  30.     public void InstanceMethod(Parent h)
  31.     {
  32.         System.out.println("InstanceMethod(Parent h)");
  33.     }
  34. }
  35.  
  36. // Output:
  37. // Calling static method with declared Parent of type Child.
  38. // StaticMethod(Parent h)
  39. // InstanceMethod(Parent h)
Add Comment
Please, Sign In to add comment