?? testinterface.java
字號:
interface Shapes {
abstract double GetArea(); //面積
abstract double GetPeri(); //周長
}
class Square implements Shapes {
public int width,height; //正方形的寬和高
Square(int width,int height) { //構造函數
this.width=width;
this.height=height;
}
public double GetArea() { //正方形的面積
return(width*height);
}
public double GetPeri() { //正方形的周長
return(2*width+2*height);
}
}
class Circle implements Shapes {
public int width,height;
public double r; //圓的半徑
Circle(int width,int height) { //構造函數
this.width=width;
this.height=height;
r=(double)width/2.0;
}
public double GetArea() { //圓的面積
return(r*r*3.1415);
}
public double GetPeri() { //圓的周長
return(2*3.1415*r);
}
}
class TestInterface {
public static void main(String[] args) {
Square NewSquare=new Square(35,35);
Circle NewCircle=new Circle(35,35);
System.out.println("正方形的面積:"+NewSquare.GetArea());
System.out.println("正方形的周長:"+NewSquare.GetPeri());
System.out.println("圓的面積:"+NewCircle.GetArea());
System.out.println("圓的周長:"+NewCircle.GetPeri());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -