public abstract class TuAn {
abstract void zhouchang();
abstract void mianji();
}这是抽象类;public class FangXing extends TuAn {
public int a;
public int b;
public void setA(int a) {
this.a = a;
System.out.println("a=" + a);
}
public void setB(int b) {
this.b = b;
System.out.println("b=" + b);
}
@Override
void zhouchang() {
// TODO Auto-generated method stub
System.out.println("a=" + a);
System.out.println("b=" + b);
System.out.println((2 * (a + b)));
}
@Override
void mianji() {
// TODO Auto-generated method stub
System.out.println(a * b);
}
}public class YuanXing extends TuAn {
int r;
void zhouchang() {
// TODO Auto-generated method stub
System.out.println(2 * 3.14 * r);
}
@Override
void mianji() {
// TODO Auto-generated method stub
System.out.println(3.14 * r * r);
}
public void setR(int r) {
this.r = r;
}
}import java.util.Scanner;
public class Initial1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TuAn tuan1 = new FangXing();
TuAn tuan2 = new YuanXing();
Scanner scr = new Scanner(System.in);
FangXing a = new FangXing();
YuanXing b = new YuanXing();
a.setA(scr.nextInt());
a.setB(scr.nextInt());
tuan1.zhouchang();
tuan1.mianji();
b.setR(scr.nextInt());
tuan2.zhouchang();
tuan2.mianji();
scr.close();
}
}结果就出现问题了 ,求指导;
添加回答
举报
0/150
提交
取消