Visibility Tests

import test.*;

class C
{
   C() {}
   public int bn(B b) { return b.n; }
   public int an(A a) { return a.n; }
   public int Bs()    { return B.s; }
}

class A
{
   int n;
   static int s = 19;

   A(int x) { n = x; }
   public int an() { return n; }
   public int Bs() { return B.s; }
}

class B extends A
{
   static int s = 21;
   B(int x) { super(x); }
   public int bn() { return n; }
}

public class Visible
{
   public static void main(String arg[])
   {
      A a = new A(10);
      B b = new B(12);
      C c = new C();
      D d = new D(14);

      //  Visibility of just variable
      System.out.println("a.an():\t"+a.an()); // 10 - same class
      System.out.println("b.bn():\t"+b.bn()); // 12 - super class
      System.out.println("d.dn():\t"+d.dn()); // 14 - across package, same cls
      // System.out.println("A.n:\t"+A.n);    // "Undefined var n"

      //  Visibility through objects
      System.out.println("a.n:\t"+a.n);       // 10 - same class
      System.out.println("b.n:\t"+b.n);       // 12 - super class
      System.out.println("c.an(a):"+c.an(a)); // 10 - other class
      System.out.println("c.bn(b):"+c.bn(b)); // 12 - other class
      // System.out.println("d.n:\t"+d.n);    // NA - across package, same cls

      // Visibility of static variables
      System.out.println("A.s:\t"+A.s);       // 19 - same class
      System.out.println("a.Bs():\t"+a.Bs()); // 21 - super class
      System.out.println("c.Bs():\t"+c.Bs()); // 21 - other class
      // System.out.println("D.s:\t"+D.s);    // NA - across package,same cls
   }
}