Advertisement
CSenshi

OOP- f2018

Jul 1st, 2019
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package f2018;
  2.  
  3. public class Child extends Parent {
  4.     public int n = 3;
  5.  
  6.     public Child() {
  7.         System.out.println("child : " + this.toString());
  8.         init();
  9.     }
  10.  
  11.     public void init() {
  12.         n = 4;
  13.     }
  14.  
  15.     public void foo() {
  16.         super.foo();
  17.         System.out.println(this.bar() + " " + this.n++);
  18.     }
  19.  
  20.     public int bar() {
  21.         return n++;
  22.     }
  23.  
  24.     public static void main(String args[]) {
  25.         ((Parent) new Child()).foo();
  26.         new Child().foo();
  27.     }
  28. }
  29.  
  30. class Parent {
  31.     public int n = 2;
  32.  
  33.     public Parent() {
  34.         System.out.println("Parr : " + this.toString());
  35.         init();
  36.     }
  37.  
  38.     public void init() {
  39.         n = 1;
  40.     }
  41.  
  42.     public void foo() {
  43.         System.out.println(this.toString());
  44.         System.out.println(this.bar() + " " + ++this.n);
  45.     }
  46.  
  47.     public int bar() {
  48.         return ++n;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement