Visibility

                                            D.java      Applet      Java Source

// Classes D.class, C.class are a package called "mypackage"
// and are located in subdirectory mypackage
import mypackage.*;
import java.awt.*;

class A
{
   int a_int;
   private int a_private_int;
   protected int a_protected_int;
   public int a_public_int;
   static int a_static_int = 100;
   private static int a_private_static_int = 101;
   protected static int a_protected_static_int = 102;
   public static int a_public_static_int = 103;

   A (int x)
   {
      a_int = x;
      a_private_int = x+1;
      a_protected_int = x+2;
      a_public_int = x+3;
   }
   
   int a() { return a_int; }
   int a_private() { return a_private_int; }
   int a_protected() { return a_protected_int; }
   int a_public() { return a_public_int; }
   int a_static() { return a_static_int; }
   int a_private_static() { return a_private_static_int; }
   int a_protected_static() { return a_protected_static_int; }
   int a_public_static() { return a_public_static_int; }   
   
   int B_a_static() { return B.a_static_int; }
   // Variable a_pri... in class B not accessible from class A
   // int B_a_private_static() { return B.a_private_static_int; }
   int B_a_protected_static() { return B.a_protected_static_int; }
   int B_a_public_static() { return B.a_public_static_int; }   
   int B_a() { return B.a_int; }
   int B_a_private() { return B.a_private_int; }
   int B_a_protected() { return B.a_protected_int; }
   int B_a_public() { return B.a_public_int; }   
}

class B extends A
{
   static int a_static_int = 110;
   private static int a_private_static_int = 111;
   protected static int a_protected_static_int = 112;
   public static int a_public_static_int = 113;

   B (int x) { super(x); }
   
   int b() { return a_int; }
   // Variable a_private_int in class A not accessible from class B
   // int b_private() { return a_private_int; }
   int b_protected() { return a_protected_int; }
   int b_public() { return a_public_int; }
   int b_static() { return a_static_int; }
   int b_private_static() { return a_private_static_int; }
   int b_protected_static() { return a_protected_static_int; }
   int b_public_static() { return a_public_static_int; }   
}

public class Visible extends java.applet.Applet
{
   TextArea text;
   public void init ()
   {
      add(text = new TextArea(30,60));

      A a = new A(10);
      B b = new B(12);
      // Cannot access this class from here - only public classes
      // C c = new C(14);
      D d = new D(16);

      text.append("a.a_int:\t\t\t"+a.a_int+"\n");
      text.append("a.a_private_int:\t\tVariable in A not accessible from Visible\n");
      text.append("a.a_protected_int:\t\t"+a.a_protected_int+"\n");
      text.append("a.a_public_int:\t\t"+a.a_public_int+"\n");
      
      text.append("a.a_static_int:\t\t"+a.a_static_int+"\n");
      text.append("a.a_private_static_int:\tVariable in A not accessible from Visible\n");
      text.append("a.a_protected_static_int:\t"+a.a_protected_static_int+"\n");
      text.append("a.a_public_static_int:\t"+a.a_public_static_int+"\n");

      text.append("\n");
      
      text.append("b.a_int:\t\t\t"+b.a_int+"\n");
      text.append("b.a_private_int:\t\tVariable in B not accessible from Visible\n");
      text.append("b.a_protected_int:\t"+b.a_protected_int+"\n");
      text.append("b.a_public_int:\t\t"+b.a_public_int+"\n");
      
      text.append("b.a_static_int:\t\t"+b.a_static_int+"\n");
      text.append("b.a_private_static_int:\tVariable in B not accessible from Visible\n");
      text.append("b.a_protected_static_int:\t"+b.a_protected_static_int+"\n");
      text.append("b.a_public_static_int:\t"+b.a_public_static_int+"\n");
      
      text.append("\n");
      
      text.append("a.B_a():\t\t\t"+a.B_a()+"\n");
      text.append("a.B_a_private():\t\t"+a.B_a_private()+"\n");
      text.append("a.B_a_protected():\t\t"+a.B_a_protected()+"\n");
      text.append("a.B_a_public():\t\t"+a.B_a_public()+"\n");
      
      text.append("a.B_a_static():\t\t"+a.B_a_static()+"\n");
      text.append("a.B_a_private_static():\tVariable in B not accessible from A\n");
      text.append("a.B_a_protected_static():\t"+a.B_a_protected_static()+"\n");
      text.append("a.B_a_public_static():\t"+a.B_a_public_static()+"\n");
         
      text.append("\n");

      text.append("b.a():\t\t\t"+b.a()+"\n");
      text.append("b.a_private():\t\t"+b.a_private()+"\n");
      text.append("b.a_protected():\t\t"+b.a_protected()+"\n");
      text.append("b.a_public():\t\t"+b.a_public()+"\n");

      text.append("b.a_static():\t\t"+b.a_static()+"\n");
      text.append("b.a_private_static():\t"+b.a_private_static()+"\n");
      text.append("b.a_protected_static():\t"+b.a_protected_static()+"\n");
      text.append("b.a_public_static():\t"+b.a_public_static()+"\n");
      
      text.append("\n");

      text.append("b.b():\t\t\t"+b.b()+"\n");
      text.append("b.b_private():\t\tVariable in A not accessible from B\n");
      text.append("b.b_protected():\t\t"+b.b_protected()+"\n");
      text.append("b.b_public():\t\t"+b.b_public()+"\n");
      
      text.append("b.b_static():\t\t"+b.b_static()+"\n");
      text.append("b.b_private_static():\t"+b.b_private_static()+"\n");
      text.append("b.b_protected_static():\t"+b.b_protected_static()+"\n");
      text.append("b.b_public_static():\t"+b.b_public_static()+"\n");

      text.append("\n");

      text.append("d.d():\t\t\t"+d.d()+"\n");
      text.append("d.d_private():\t\tVariable in C not accessible from D\n");
      text.append("d.d_protected():\t\t"+d.d_protected()+"\n");
      text.append("d.d_public():\t\t"+d.d_public()+"\n");

      text.append("d.d_static():\t\t"+d.d_static()+"\n");
      text.append("d.d_private_static():\t"+d.d_private_static()+"\n");
      text.append("d.d_protected_static():\t"+d.d_protected_static()+"\n");
      text.append("d.d_public_static():\t"+d.d_public_static()+"\n");
      
      text.append("\n");
      
      text.append("d.c():\t\t\t"+d.c()+"\n");
      text.append("d.c_private():\t\t"+d.c_private()+"\n");
      text.append("d.c_protected():\t\t"+d.c_protected()+"\n");
      text.append("d.c_public():\t\t"+d.c_public()+"\n");

      text.append("d.c_static():\t\t"+d.c_static()+"\n");
      text.append("d.c_private_static():\t"+d.c_private_static()+"\n");
      text.append("d.c_protected_static():\t"+d.c_protected_static()+"\n");
      text.append("d.c_public_static():\t"+d.c_public_static()+"\n");
      
      text.append("\n");
      
      text.append("d.c:\t\t\tVariable in D not accessible from Visible\n");
      text.append("d.c_private:\t\tVariable in D not accessible from Visible\n");
      text.append("d.c_protected:\t\tVariable in D not accessible from Visible\n");
      text.append("d.c_public:\t\t"+d.c_public_int+"\n");

      text.append("d.c_static:\t\tVariable in D not accessible from Visible\n");
      text.append("d.c_private_static:\tVariable in D not accessible from Visible\n");
      text.append("d.c_protected_static:\tVariable in D not accessible from Visible\n");
      text.append("d.c_public_static:\t\t"+d.c_public_static_int+"\n");
      
      text.append("\n");
   }
}