利用接口及抽象类设计实现
1.定义接口圆形CircleShape(),其中定义常量PI,默认方法area计算圆面积。 2.定义圆形类Circle实现接口CircleShape,包含构造方法与求周长方法。 3.定义圆柱继承Circle实现接口CircleShape,包含构造方法,圆柱表面积,体积。 4.从控制台输入圆半径,输出圆面积及周长。 5.从控制台输入圆柱底面半径及高,输出圆柱底面积、圆柱表面积及体积。 public class yuan { public static void main(String[] args) { Circle test=new Circle(5); System.out.println("周长为"+test.makec()); System.out.println("面积为"+test.area(test.ban)); Cylinder test2=new Cylinder(10, 5); System.out.println("圆柱底面积为"+test2.dimianji()); System.out.println("圆柱表面积为"+test2.getbmj()); System.out.println("圆柱体积为"+test2.gettj()); } } interface CircleShape{ public double PI=3.1415926535;