java吧 关注:1,240,840贴子:12,714,677
  • 3回复贴,共1
import java.util.*;
import javax.swing.*;
class circle
{
public double r;
public circle(double r)
{
this.r=r;
}
public double getarea(){
return ((Math.PI)*r*r);
}
public double getperimeter(){
return (2*(Math.PI)*r);
}
public void setr(double R){
r=R;
}
public double getr(){
return r;
}
}
class yuanzhui extends circle
{
double h;
  
public yuanzhui(double h)
{this.h=h;} ///////为什么这里会有问题
public double gettiji(){
return (1/3*getarea()*h);
}
public double geth(){
return h;
}
public void seth(double H){
h=H;
}
}
class yuanzhu extends circle
{
double h;
public yuanzhu(double h)
{
this.h=h; ///////为什么这里会有问题
}
public double gettiji(){
return (getarea()*h);
}
public double geth(){
return h;
}
public void seth(double H){
h=H;
}
}
public class test{
public static void main(String args[])
{
yuanzhu yzu;
yzu=new yuanzhu(3.0);
yuanzhui yzui;
yzui=new yuanzhui(4.0);
System.out.print(yzu.gettiji());
System.out.print(yzui.gettiji());
}
}


IP属地:浙江1楼2011-03-23 23:00回复
    Implicit super constructor circle() is undefined. Must explicitly invoke another constructor。
    class circle {
        public double r;
    //    public circle(){}
        public circle(double r) {
            this.r = r;
        }
        public double getarea() {
            return ((Math.PI) * r * r);
        }
        public double getperimeter() {
            return (2 * (Math.PI) * r);
        }
        public void setr(double R) {
            r = R;
        }
        public double getr() {
            return r;
        }
    }
    给这个类   加上一个空的 构造方法 就可以了
    


    2楼2011-03-24 10:49
    回复
      如果想仔细理解 。 就看看 java 反射机制。 类加载,调用


      3楼2011-03-24 10:54
      回复
        谢谢


        IP属地:浙江4楼2011-03-24 16:36
        回复