double perimeter = 0
double area = 0
public abstract double calPerimeter()
public abstract double calArea()
public double getPerimeter()
public double getArea()
}
public class Circular implements Shape {
private final double PI = 3.1415926
private double Radius
public Circular(double radius) {
this.Radius = radius
}
@Override
public double calPerimeter() {
// TODO Auto-generated method stub
return Radius * PI * 2
}
@Override
public double calArea() {
// TODO Auto-generated method stub
return Radius * Radius * PI
}
public double getRadius() {
return Radius
}
public void setRadius(double radius) {
Radius = radius
}
public double getPI() {
return PI
}
@Override
public double getPerimeter() {
// TODO Auto-generated method stub
return calPerimeter()
}
@Override
public double getArea() {
// TODO Auto-generated method stub
return calArea()
}
}
public class ShapeTestDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Circular cir = new Circular(3)
System.out.println(cir.calArea())
System.out.println(cir.calPerimeter())
System.out.println(cir.getPI())
System.out.println(cir.getArea())
}
}
publicinterface
人
-----------接口;
{
public
void
吃饭()----------
接口中的方法;
}
---------------------------------
接口的实现类;
public
class
男人
implements
人
{
public
void
吃饭()
------它实现了上面的接口,它就必
-----需实现上面的方法;
{
System.out.println("真好吃")
}
public
void
挣钱()
------在实现类中还可以写自己的方法
{
System.out.println("真累啊")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)