import static java.lang.Math.*;
import java.util.*;
interface Shape{
void areas();
}
class rectangle implements Shape{
float h,w;
public rectangle(float h,float w){
this.h=h;
this.w=w;
}
public void areas(){
System.out.println("rectangle 面積為:"+h*w);
}
}
class square implements Shape{
float h;
public square(float h){
this.h=h;
}
public void areas(){
System.out.println("square 面積為:"+h*h);
}
}
class round implements Shape{
float r;
public round(float r){
this.r=r;
}
public void areas(){
System.out.println("round 面積為:"+PI*r*r);
}
}
class test{
public static void main(String[]args){
rectangle r=new rectangle(5,3);
square s=new square(5);
round ro=new round(3);
r.areas();
s.areas();
ro.areas();
}
}
取消
評論