1、源代码ui
package jiekou;this
public class jiekou {
public static void main (String[] arges){
yuanzhui a=new yuanzhui(1,2,3);
yuanzhui b=new yuanzhui(4,5,6);
System.out.println(a.Area());
System.out.println(b.Area());
System.out.println(a.volume());
System.out.println(b.volume());
System.out.println("体积较大的是:"+Math.max(a.volume(), b.volume()));
}
blog
}
class yuanzhui implements Volume,Area{
protected double r;
protected double l;
protected double h;
public yuanzhui(double r,double l,double h){
this.r=r;
this.l=l;
this.h=h;
}
public double volume(){
return Math.PI*Math.pow(r,2)*h/3;
}
public double Area(){
return Math.PI*this.r*this.r+this.r*this.l;
}
}
interface Volume{
public double volume();
}
interface Area{
public double Area();
}继承
2、结果接口
3、心得class
一、Java接口是一系列方法的声明,是一些方法特征的集合,一个接口只有方法的特征没有方法的实现,所以这些方法能够在不一样的地方被不一样的类实现,而这些实现能够具备不一样的行为(功能)。方法
二、接口指明了一个类必需要作什么和不能作什么,至关于类的蓝图。im
三、由于Java不像C++同样支持多继承,因此Java能够经过实现接口来弥补这个局限。static
四、为了声明一个接口,咱们使用interface这个关键字img
五、接口被用来描述一种抽象。