Java 抽象函数

abstract class tx{
String name;
float a,b;
public  tx(String name){
this.name=name;
 
}
abstract public void mj();
abstract public void zc();
}
 
class yuan extends tx{
public static final float pai=(float) 3.1415;
float r;
public yuan(String name,float r){
super(name);
this.r=r;
}
public void mj(){
System.out.println("圆的面积"+pai*r*r);
}
public void zc(){
System.out.println("圆的周长"+2*pai*r);
}
 
}
 
class fang extends tx{
int a,b;
public fang(String name,int a,int b){
super(name);
this.a=a;
this.b=b;
}
public void mj(){
System.out.println("方的面积"+a*b);
}
public void zc(){
System.out.println("方的周长"+(a+b)*2);
}
 
}
 
public class Dmo1 {
 
public static void main(String[] args) {
yuan y=new yuan("圆",(float) 5.00);
y.zc();
y.mj();
fang f=new fang("方",5,3);
f.zc();
f.mj();
}
 
}

猜你喜欢

转载自www.cnblogs.com/3w1z3/p/10878199.html