Программирование на языке Java


Пакеты и интерфейсы - часть 5


 

package р1;

public class Protection {

int n = 1;

private int n_pri = 2;

protected int n_pro = 3;

private protected int n_pripro = 4;

public int n_pub = 5;

public Protection() {

System.out.println("base constructor");

System.out.println("n = " + n);

System.out.println("n_pri = " + n_pri);

System.out.println("n_pro = "  + n_pro);

System.out.println("n_pripro = " + n_pripro);

System.out.println("n_pub = " + n_pub);

} }

class Derived extends Protection {

Derived() {

          System.out.println("derived constructor");

          System.out.println("n = " + n);

          // только в классе

          // System.out.println("n_pri = " + n_pri);

          System.out.println("n_pro = "    + n_pro);

          System.out.println("n_pripro = " + n_pripro);

          System.out.println("n_pub = "    + n_pub);

} }

class  SamePackage {

SamePackage() {

              Protection p = new Protection();

              System.out.println("same package constructor");

              System.out.println("n = " + p.n);

              // только в классе

              // System.out.println("n_pri = " + p.n_pri);




Начало  Назад  Вперед