应用Rangle1定义子类正方形Square
2011-02-16 16:43
176 查看
定义矩形接口rect
在接口中有计算面积area()
获取宽度getWidth()
获取高度getHeight()
获取矩形位置getLocation()
继承接口rect实现矩形类Rentangle
编写应用Rangle1定义子类正方形Square
//定义矩形接口rect,
interface rect {
//在接口中有计算面积area()、
public long area();
//获取宽度getWidth()、
public long getWidth();
//获取高度getHeight()、
public long getHeight();
//获取矩形位置getLocation()等的方法。
public String getLocation();
public void setHeight(long height);
public void setWidth(long width);
public void setX(String x);
public void setY(String y);
}
//编写继承接口rect实现矩形类Rentangle。
class Rentangle implements rect {
private long height;
private long width;
private String x;
private String y;
public long getHeight() {
return this.height;
}
public long getWidth() {
return this.width;
}
public void setHeight(long height) {
this.height = height;
}
public void setWidth(long width) {
this.width = width;
}
public void setX(String x) {
this.x = x;
}
public void setY(String y) {
this.y = y;
}
public long area() {
return this.height*this.width;
}
public String getLocation() {
return "" + this.x + "," + this.y + "";
}
}
//应用Rangle1类。
public class UseRentangle {
public static void main(String[] args) {
rect Rangle1 = new Rentangle();
Rangle1.setHeight(100);
Rangle1.setWidth(200);
Rangle1.setX("10");
Rangle1.setY("20");
System.out.println(Rangle1.area());
System.out.println(Rangle1.getLocation());
rect square = new Square();
square.setHeight(100);
square.setX("30");
square.setY("50");
System.out.println(square.area());
System.out.println(square.getLocation());
}
}
//编写程序,通过继承Rangle1类定义子类正方形Square。至少编写方法覆盖area(),并实现之。
class Square extends Rentangle {
private long height;
private String x;
private String y;
public long getHeight() {
return this.height;
}
public long getWidth() {
return this.height;
}
public void setHeight(long height) {
this.height = height;
}
public void setWidth(long height) {
this.height = height;
}
public void setX(String x) {
this.x = x;
}
public void setY(String y) {
this.y = y;
}
public long area() {
return this.height*this.height;
}
public String getLocation() {
return "" + this.x + "," + this.y + "";
}
}
在接口中有计算面积area()
获取宽度getWidth()
获取高度getHeight()
获取矩形位置getLocation()
继承接口rect实现矩形类Rentangle
编写应用Rangle1定义子类正方形Square
//定义矩形接口rect,
interface rect {
//在接口中有计算面积area()、
public long area();
//获取宽度getWidth()、
public long getWidth();
//获取高度getHeight()、
public long getHeight();
//获取矩形位置getLocation()等的方法。
public String getLocation();
public void setHeight(long height);
public void setWidth(long width);
public void setX(String x);
public void setY(String y);
}
//编写继承接口rect实现矩形类Rentangle。
class Rentangle implements rect {
private long height;
private long width;
private String x;
private String y;
public long getHeight() {
return this.height;
}
public long getWidth() {
return this.width;
}
public void setHeight(long height) {
this.height = height;
}
public void setWidth(long width) {
this.width = width;
}
public void setX(String x) {
this.x = x;
}
public void setY(String y) {
this.y = y;
}
public long area() {
return this.height*this.width;
}
public String getLocation() {
return "" + this.x + "," + this.y + "";
}
}
//应用Rangle1类。
public class UseRentangle {
public static void main(String[] args) {
rect Rangle1 = new Rentangle();
Rangle1.setHeight(100);
Rangle1.setWidth(200);
Rangle1.setX("10");
Rangle1.setY("20");
System.out.println(Rangle1.area());
System.out.println(Rangle1.getLocation());
rect square = new Square();
square.setHeight(100);
square.setX("30");
square.setY("50");
System.out.println(square.area());
System.out.println(square.getLocation());
}
}
//编写程序,通过继承Rangle1类定义子类正方形Square。至少编写方法覆盖area(),并实现之。
class Square extends Rentangle {
private long height;
private String x;
private String y;
public long getHeight() {
return this.height;
}
public long getWidth() {
return this.height;
}
public void setHeight(long height) {
this.height = height;
}
public void setWidth(long height) {
this.height = height;
}
public void setX(String x) {
this.x = x;
}
public void setY(String y) {
this.y = y;
}
public long area() {
return this.height*this.height;
}
public String getLocation() {
return "" + this.x + "," + this.y + "";
}
}
相关文章推荐
- 设计一个形状类Shape,方法:求周长和求面积 形状类的子类:Rect(矩形),Circle(圆形) Rect类的子类:Square(正方形)
- Android 应用的 UI 设计师应当如何如何定义字体的 sp 值
- bzoj 2509 送分题 && SNOI省选模拟赛Round3 T3 正方形square 树状数组
- 软件定义其实是应用定义
- 父类私有变量是否被子类继承详细解说(答案:内存中存在,但sun公司定义为不继承)
- 扩展欧几里德算法的定义、解释、证明及其应用
- 【c++】memset定义极值在竞赛中的应用
- 华软通信短信验证码定义及应用
- 常见设计模式的定义,应用场景和方法
- c/c++结构体定义以及结合typedef的应用
- C# 接口属性的定义&get、set访问器的简单应用
- Command的定义和应用
- 枚举类型的定义和应用
- WP7上传应用时报“不能为后台代理AudioPlayAgent定义超过一个实例”解决方案。
- 接口的实际应用--定义标准
- 编译Spark应用代码报对象已定义错误
- oracle ebs应用产品安全性-定义访问权限集
- 十佳应用的故事 - 想法、产品定义与交互设计
- LeetCode: 221_Maximal Square | 二维0-1矩阵中计算包含1的最大正方形的面积 | Medium