Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. class Egg2 {
  2. protected class Yolk {
  3. public Yolk() {
  4. System.out.println("Egg2.Yolk()");
  5. }
  6.  
  7. public void f() {
  8. System.out.println("Egg2.Yolk.f()");
  9. }
  10. }
  11.  
  12. private Yolk y = new Yolk();
  13.  
  14. public Egg2() {
  15. System.out.println("New Egg2()");
  16. }
  17.  
  18. public void insertYolk(Yolk yy) {
  19. y = yy;
  20. }
  21.  
  22. public void g() {
  23. y.f();
  24. }
  25. }
  26.  
  27. public class BigEgg2 extends Egg2 {
  28. public class Yolk extends Egg2.Yolk {
  29. public Yolk() {
  30. System.out.println("BigEgg2.Yolk()");
  31. }
  32.  
  33. public void f() {
  34. System.out.println("BigEgg2.Yolk.f()");
  35. }
  36. }
  37.  
  38. public BigEgg2() {
  39. insertYolk(new Yolk());
  40. }
  41.  
  42. public static void main(String[] args) {
  43. Egg2 e2 = new BigEgg2();
  44. e2.g();
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement