日期:2014-05-20  浏览次数:20710 次

java bPoint.x 这样用可以吗
public class Point{

  private long x ;
  private long y ;

  public Point(long x ,long y){
  this.x = x ;
  this.y = y ;
}
}
class Graphics{

  public long perimeter() ;
  public long area() ;
}

class Rectangle extends Graphics{
  private Point bPoint ;
  private Point ePoint ;

  public Rectangle(){}  
  public Rectangle(Point bPoint, Point ePoint){
  this.bPoint = bPoint ;
  this.ePoint = ePoint ;
  }

public long perimeter() {
  return (Math.abs(bPoint.x-ePoint.x)+Math.abs(bPoint.y-

ePoint.y))*2;  
}  
public long area() {
  return Math.abs(bPoint.x-ePoint.x)*Math.abs(bPoint.y-

ePoint.y);
}
}
public class PassTest3{
  public static void main(String[] args){
  Graphics g = new Rectangle(new Point(0, 1), new Point(5,5));
  System.out.println(g.area() + "----" + g.perimeter());
  }
}

------解决方案--------------------
不可以 私有属性不能直接访问,你可以通过getter/setter方法访问