Advertisement
Guest User

Untitled

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