首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

java bPoint.x 这样用可以吗,该怎么处理

2012-04-21 
java bPoint.x 这样用可以吗public class Point{private long x private long y public Point(long x ,l

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方法访问

热点排行