//Point.java
public class Point {
private int x;
private int y;
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 Point(int x, int y) {
this.x=x;
this.y=y;
}
}
//Rectangle.java
public class Rectangle extends Point{
private int x;
private int y;
private int width;
private int height;
public Rectangle(int x, int y) {
super(x, y);
// TODO Auto-generated constructor stub
}
public Rectangle(int x2, int y2, int width, int height) {
super(x2, y2);
this.x = x2;
this.y = y2;
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
//Cube.java
public class Cube extends Point{
private int x;
private int y;
private int z;
private int length;
private int width;
private int heigth;
public Cube(int x, int y, int z, int length, int width,
int heigth) {
super(x, y);
x = x;
y = y;
this.z = z;
this.length = length;
this.width = width;
this.heigth = heigth;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeigth() {
return heigth;
}
public void setHeigth(int heigth) {
this.heigth = heigth;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
}
//测试类T.java
import java.awt.*;
import java.awt.event.*;
public class T{
public static void main(String args[]) {
Point p = new Point(1,2);
Rectangle r = new Rectangle(5,5,200,300);
Cube c = new Cube(10,10,10,15,10,25);
System.out.print("长方形的位置、长、宽分别为:");
System.out.println("("+r.getX()+","+r.getY()+")、"+r.getWidth()+"、"+r.getHeight());
System.out.print("立方体的位置、长、宽、高分别为:");
System.out.println("("+c.getX()+","+c.getY()+","+c.getZ()+")、"+c.getLength()+"、"+c.getWidth()+"、"+c.getHeigth());
}
}
您的进步是我最大的动力,如果你觉得我回答的合理的话,请给我多加分。谢谢,如果不明白的话,大家相互学习啊!
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
vaela
温馨提示:答案为网友推荐,仅供参考