1,创建A接口
package com.demo005;
public interface A {
double pi = Math.PI;
abstract double area();
}
2,创建B接口
package com.demo005;
public interface B {
void setColor(String color);
}
3,创建C接口
package com.demo005;
public interface C extends A,B{
abstract void volume();
}
4,创建主体类
package com.demo005;
public class Cylinder implements C{
private double radius;
private double height;
private String color;
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public String getColor() {
return color;
}
public Cylinder(double radius, double height, String color) {
this.radius = radius;
this.height = height;
this.color = color;
}
@Override
public double area() {
return pi*radius*radius;
}
@Override
public void setColor(String color) {
System.out.println(this.color);
}
@Override
public void volume() {
System.out.println(pi*radius*radius*height);
}
}
4,测试类,以及测试图
package com.demo005;
public class Test {
public static void main(String[] args) {
Cylinder cylinder=new Cylinder(2,3,"green");
System.out.println("底面积:"+cylinder.area());
System.out.print("体积:");
cylinder.volume();
System.out.print("颜色:");
cylinder.setColor("green");
}
}