
主要代码
import java.util.Scanner;class Circle {
public double r;
public double get_r(double r){
return r; }
public void set_r(double r) {
this.r= r; }public double getArea() {
return Math.PI
rr; }
public double getPeriometer() { return 2Math.PIr; }
}
class YuanZhu extends Circle{
private Circle bottom; private double h; public YuanZhu() { super(); }public YuanZhu(Circle bottom) {
super(); this.bottom = bottom; }public YuanZhu(double h) {
super(); this.h = h; }public YuanZhu(Circle bottom,double h) {
super(); this.bottom = bottom; this.h = h; }public double getVolume() {
return this.bottom.getArea()*h; }public double getBiaoMian() {
return this.bottom.getArea()*2+this.bottom.getPeriometer()*h; }}public class test1 {
public static void main(String[] args) {
double r=10,h=20;Circle c1 = new Circle();
YuanZhu Y1 = new YuanZhu();
System.out.printf("圆的面积:");
c1.getArea(); System.out.printf("圆的体积:"); c1.getPeriometer();System.out.printf("圆柱的表面积:");
Y1.getBiaoMian(); System.out.printf("圆柱的体积:");
Y1.getVolume(); }}

getVolume()函数就不空 getBiaoMian()怎么就空呢
你得给他赋值啊,没有bottom的值不为空才怪了

public static void main(String[] args) {
double r=10,h=20;
Circle c1 = new Circle();
c1.set_r(r);
YuanZhu Y1 = new YuanZhu(c1,h);
System.out.printf("圆的面积:"+c1.getArea());
System.out.printf("圆的体积:"+c1.getPeriometer());
System.out.printf("圆柱的表面积:"+ Y1.getBiaoMian());
System.out.printf("圆柱的体积:"+Y1.getVolume());
}