Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package f2018;
- public class Child extends Parent {
- public int n = 3;
- public Child() {
- System.out.println("child : " + this.toString());
- init();
- }
- public void init() {
- n = 4;
- }
- public void foo() {
- super.foo();
- System.out.println(this.bar() + " " + this.n++);
- }
- public int bar() {
- return n++;
- }
- public static void main(String args[]) {
- ((Parent) new Child()).foo();
- new Child().foo();
- }
- }
- class Parent {
- public int n = 2;
- public Parent() {
- System.out.println("Parr : " + this.toString());
- init();
- }
- public void init() {
- n = 1;
- }
- public void foo() {
- System.out.println(this.toString());
- System.out.println(this.bar() + " " + ++this.n);
- }
- public int bar() {
- return ++n;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement