您的位置首页百科知识

为什么我的程序老是在main方法里出错main(String[] args)就是这里,哪位高人帮我看看,谢谢了。

为什么我的程序老是在main方法里出错main(String[] args)就是这里,哪位高人帮我看看,谢谢了。

的有关信息介绍如下:

为什么我的程序老是在main方法里出错main(String[] args)就是这里,哪位高人帮我看看,谢谢了。

给你改了一下 不过建议不要把几个类放在一个java文件里 RecteTest.javapublic class RecteTest { public static void main(String[] args) { Recter ry = new Recter(10.5f, 5.5f, 6.5f); System.out.println(ry); }}class Recte { private float length; private float width; public Recte() { } public Recte(float length, float width) { this.length = length; this.width = width; } public float getLength() { return length; } public void setLength(float length) { this.length = length; } public float getWidth() { return width; } public void setWidth(float width) { this.width = width; } @Override public String toString() { String s = "长度:" + length + ",宽度:" + width; return s; } public float getPerimeter() { float perimeter = length * 2 + width * 2; return perimeter; } public float getArea() { float area = length * width; return area; }}class Recter extends Recte{ private float height; public Recter() { super(); } public Recter(float length, float width, float height) { super(length, width); this.height = height; } public float getHeight() { return height; } public void setHeight(float height) { this.height = height; } public float getVolume() { float volume = getArea() * height; return volume; } @Override public String toString() { String s = "矩形长度:" + getLength() + ",矩形宽度:" + getWidth() + ",长方体的高度:" + height + ",矩形底面积:" + getArea() + ",长方体体积:" + getVolume(); return s; } }