应用Rangle1定义子类正方形Square
来源:互联网 发布:淘宝买家退回货物不符 编辑:程序博客网 时间:2024/05/16 00:25
定义矩形接口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 + "";
}
}
- 应用Rangle1定义子类正方形Square
- 最大正方形 (Largest Square)
- Maximal Square 最大的正方形
- [Leetcode] Maximal Square 最大正方形
- **[Lintcode]Maximal Square 最大正方形
- Square= =……拼正方形
- 填充正方形(Fill the Square)
- UVa 11520 Fill the Square 填充正方形
- LeetCode 221. Maximal Square(最大正方形)
- Maximal Square 面积最大的正方形
- 1661: [Usaco2006 Nov]Big Square 巨大正方形
- HDU1518——Square(正方形问题)
- Leetcode—221.Maximal Square 最大正方形
- 221. Maximal Square (最大正方形)
- leetcode 593. Valid Square 正方形的判定
- UVa Problem 10270 Bigger Square Please... (拼接正方形)
- UVa Problem 10270 Bigger Square Please... (拼接正方形)
- UVa 11520 - Fill the Square (填充正方形)
- WEB项目前台开发管理的思考
- UNIX操作系统 基础篇
- 23种设计模式
- Apache Common JXPath
- 编译器需要implicit nontrivial default constructor情况
- 应用Rangle1定义子类正方形Square
- 信息化基础的最小熵值的散点聚集
- QT 的随机函数的应用
- 直接插入排序算法
- java 获取客户端ip mac地址
- iframe 中获取编辑器对象
- 宏的一些副作用
- .Net技术架构
- const,static,extern,volatile,mutable用法