Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo1 {
- String bar = "bar1";
- String getBar() {
- return this.bar;
- }
- void setBar(final String bar) {
- this.bar = bar;
- }
- }
- class Foo2 extends Foo1 {
- String bar = "bar2";
- @Override
- String getBar() {
- return this.bar;
- }
- }
- public class Main {
- public static void main(final String[] args) {
- final Foo2 foo2 = new Foo2();
- final Foo1 foo1 = foo2;
- foo2.setBar("foo1");
- System.out.println(foo2.bar);
- System.out.println(foo2.getBar());
- System.out.println(foo1.bar);
- System.out.println(foo1.getBar());
- foo2.bar = "foo2";
- System.out.println(foo2.bar);
- System.out.println(foo2.getBar());
- System.out.println(foo1.bar);
- System.out.println(foo1.getBar());
- }
- }
Add Comment
Please, Sign In to add comment