Sunjaree

Child Counting(For Final)

Dec 25th, 2019
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. class G{
  2.    static int g = 0;
  3. G(){
  4.  
  5. }
  6. }
  7.  
  8. class E extends G{
  9.    static int e = 0;
  10.     E(){
  11.         g++;
  12.     }
  13. }
  14.  
  15. class Q extends G{
  16.    static int q = 0;
  17.     Q(){
  18.         g++;
  19.     }
  20. }
  21.  
  22. class A extends E{
  23.    static int a = 0;
  24.  
  25.     A(){
  26.         e++;
  27.         g--;
  28.     }
  29. }
  30.  
  31. class B extends Q{
  32.    static int b = 0;
  33.     B(){
  34.         q++;
  35.         g--;
  36.     }
  37. }
  38.  
  39. class C extends  Q{
  40.    static int c = 0;
  41.     C(){
  42.         q++;
  43.         g--;
  44.     }
  45. }
  46.  
  47. class D extends Q{
  48.   static   int d = 0;
  49.     D(){
  50.         q++;
  51.         g--;
  52.     }
  53. }
  54.  
  55. public class ChildCountingFinal {
  56.     public  static void main(String[] args){
  57.  
  58.       G ob1 = new G();
  59.        E ob2  = new E();
  60.        A ob3 = new A();
  61.        Q ob4 = new Q();
  62.        B ob5 = new B();
  63.        C ob6 = new C();
  64.        D ob7 = new D();
  65.  
  66.  
  67.  
  68.        System.out.println("G " + ob1.g);
  69.        System.out.println("E " + ob2.e);
  70.        System.out.println("A " + ob3.a);
  71.        System.out.println("Q " + ob4.q);
  72.        System.out.println("B "  + ob5.b);
  73.        System.out.println("C " + ob6.c);
  74.        System.out.println("D " + ob7.d);
  75.  
  76.  
  77.  
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment