62,625
社区成员
发帖
与我相关
我的任务
分享
public class Point{
int x;
int y;
public Point(int x, int y){
this.x = x;
this.y = y;
}
public Point() {
this(0,0);
}
public int getX(){
return x;
}
public void setX(int x){
this.x = x;
}
public int getY(){
return y;
}
public void setY(int y){
this.y = y;
}
}
public class Pixel extends Point{
private Color color;
public class Color{
int red;
int green;
int blue;
public Color(int red,int green,int blue) {
this.red=red;
this.green=green;
this.blue=blue;
}
public Color() {
this(0,0,0);
}
private String toRGBString() {
return "RGB("+this.red+","+this.green+","+this.blue+")";
}
}
public Pixel(Point p,Color color) {
super(p);
this.color=color;
}
public Pixel() {
this(new Point(0,0),new Color(0,0,0));
}
public String toString(){
return this.getClass().getName()+"像素,坐标"+super.toString()+"颜色"+this.color.toRGBString();
}
public static void main(String args[]) {
System.out.println(new Pixel().toString());
Point p=new Point(100,100);
Color c=new Color(20,15,15);
Pixel pixel=new Pixel(p,c);
System.out.println(pixel.toString());
}
}