62,614
社区成员
发帖
与我相关
我的任务
分享
package a;
import b.Rectangle;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
Rectangle r= new Rectangle(10,20,30,40);
System.out.println(r.x);
System.out.println(r.width);//private修饰 这里报错了
System.out.println(r.height);//protected 修饰 这里报错了
}
}
package b;
public class Rectangle {
//受保护的member
public int x;
protected int y;
private int width;
protected int height;
public Rectangle() {
}
public Rectangle(int x, int y,
int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
public void setWidth(int width) { this.width = width; }
public void setHeight(int height) { this.height = height; }
public int getX() { return x; }
public int getY() { return y; }
public int getWidth() { return width; }
public int getHeight() { return height; }
public int getArea() { return width*height; }
// public static void main(String[] args){
// Rectangle rect=new Rectangle(10,20,30,40);
// System.out.print(rect.width);
// System.out.print(rect.height);
// }
}