next up previous
Next: 9.2 JDK1.4でのパッケージ Up: 9 パッケージ Previous: 9 パッケージ

9.1 パッケージとアクセス制御

あるパッケージの中で,publicのクラスの中に, publicのついていないメソッドを定義した場合には そのメソッドへのアクセスはできない.

package test;

public class Point {
  int x,y;
  public Point() { 
   System.out.println("Point constructor"); 
  }
  void pos() {
    System.out.println("( "
          + x + " , " + y + " )" );
  }
}

import test.*;

public class Line {
  public Line() { 
   System.out.println("Line Constructor");
  }
  public static void main(String[] args) {
    Point p = new Point();
    // p.pos(); // アクセス不可
  }
}


generated through LaTeX2HTML. M.Inaba 平成18年5月7日