继承和多态 void报错!!!
程序代码:
package haha_111; public class Point { protected double x; protected double y; public Point(double x, double y) { this.x = x; this.y = y; } public Point() { x = y = 0; } public double getX() { return x; } public void setX(double x) { this.x = x; } public double getY() { return y; } public void setY(double y) { this.y = y; } } public class Circle extends Point { protected double r; public Circle(double x, double y, double r) { super(x, y); this.r = r; } public Circle() { super(); r = 0; } public double area() { return Math.PI * r * r; } public double getR() { return r; } public void setR(double r) { this.r = r; } } public class Cylinder extends Circle { protected double h; public Cylinder(double x, double y, double r, double h) { super(x, y, r); this.h = h; } public Cylinder() { super(); h = 0; } public double volume() { return area() * h; } public double getH() { return h; } public void setH(double h) { this.h = h; } } public static void main(String[] args) { Cylinder c1 = new Cylinder(); Cylinder c2 = new Cylinder(1, 2, 3, 4); System.out.println("c1(" + c1.getX() + "," + c1.getY() + "):r=" + c1.getR() + ",h=" + c1.getH() + ",volume=" + c1.volume()); System.out.println("c2(" + c2.getX() + "," + c2.getY() + "):r=" + c2.getR() + ",h=" + c2.getH() + ",volume=" + c2.volume()); }
一般初学者在继承和多态时候都会遇见这个题目的,程序运行报错
错误信息:"Point.java": 'class' or 'interface' expected at line 88, column 15
请高手指点! 谢谢!
[[it] 本帖最后由 hanzhu3366 于 2008-5-21 00:41 编辑 [/it]]