Guest User

Untitled

a guest
Jan 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class Foo1 {
  2. String bar = "bar1";
  3.  
  4. String getBar() {
  5. return this.bar;
  6. }
  7.  
  8. void setBar(final String bar) {
  9. this.bar = bar;
  10. }
  11. }
  12.  
  13. class Foo2 extends Foo1 {
  14. String bar = "bar2";
  15.  
  16. @Override
  17. String getBar() {
  18. return this.bar;
  19. }
  20. }
  21.  
  22. public class Main {
  23. public static void main(final String[] args) {
  24. final Foo2 foo2 = new Foo2();
  25. final Foo1 foo1 = foo2;
  26.  
  27. foo2.setBar("foo1");
  28. System.out.println(foo2.bar);
  29. System.out.println(foo2.getBar());
  30. System.out.println(foo1.bar);
  31. System.out.println(foo1.getBar());
  32.  
  33. foo2.bar = "foo2";
  34. System.out.println(foo2.bar);
  35. System.out.println(foo2.getBar());
  36. System.out.println(foo1.bar);
  37. System.out.println(foo1.getBar());
  38. }
  39. }
Add Comment
Please, Sign In to add comment