Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. public class E {
  2.  
  3. interface X { void f(); }
  4.  
  5. class B {
  6. public void g() { System.out.print("B.g() "); }
  7. }
  8.  
  9. public static void main(String[] Args) {
  10.  
  11.  
  12. class C extends B implements X {
  13. public void f() { System.out.print("C.f() "); }
  14. public void f(Object ref) { System.out.print("C.f(Object) "); }
  15.  
  16. }
  17.  
  18. abstract class A extends B implements X {
  19. public void f() { System.out.print("A.f() "); }
  20. public void g() { System.out.print("A.g() "); }
  21. public abstract B f(B ref);
  22. }
  23.  
  24. class D extends A {
  25. public static B st = new B();
  26. public void f() { System.out.print("D.f() "); }
  27. public B f(B ref) { if (ref instanceof A) return (D)ref; return st; }
  28. }
  29.  
  30.  
  31.  
  32. }
  33.  
  34. A a = new D();
  35. B b = a;
  36. b.g();
  37. a.g();
  38. a.f(b);
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement