java 接口 & 抽象类

接口 定义:

interface InVolume        //接口
{
    double calVolume();
}
interface InArea        //面积接口
{
    double calArea();
}


class Cylinder implements InVolume,InArea    //圆柱体类  实现接口  可以实现多个接口
{
    double height;         //圆柱体的高
    double radius;        //圆的半径
    public Cylinder(double r, double h) {
        this.radius=r;
        this.height=h;

    }

}

抽象类 定义:

abstract class Employee{
  public abstract double earnings(); //抽象方法
}
class YearWorker extends Employee{   //继承抽象类,只能继承一个抽象类
  public double earnings(){
  return 12000;
}
}






猜你喜欢

转载自blog.csdn.net/qq_28938403/article/details/51440408