当前位置: 代码迷 >> Java相关 >> [求助]不用超类引用,就可以直接用它
  详细解决方案

[求助]不用超类引用,就可以直接用它

热度:229   发布时间:2006-12-06 18:41:37.0
[求助]不用超类引用,就可以直接用它

我在Circle3.java中定义了radius这么一个值,但是为什么在Cylinder3.java中不加定义,也不用超类引用,就可以直接用它.
package c.czg;

import c.czg.Point3;

public class Circle3 extends Point3
{
protected double radius;

public Circle3()
{
setRadius(0.0);
}

public Circle3( double circleRadius,int xCoordinate,int yCoordinate )
{
super( xCoordinate,yCoordinate );
setRadius( circleRadius );
}

public void setRadius( double circleRadius )
{
radius = ( circleRadius >= 0.00 ? circleRadius : 0.00 );
}

public double getRadius()
{
return radius;
}

public double area()
{
return Math.PI * radius * radius;
}

public String toString()
{
return "Center = " + super.toString() +
"; Radius = " + radius;
}

public String getName()
{
return "Circle:";
}
}

package c.czg;

import c.czg.Circle3;

public class Cylinder3 extends Circle3
{
protected double height;

public Cylinder3()
{
setHeight(0);
}

public Cylinder3( double cylinderHeight,double cylinderRadius,int xCoordinate,int yCoordinate)
{
super( cylinderRadius,xCoordinate,yCoordinate );
setHeight( cylinderHeight );
}

public void setHeight( double cylinderHeight )
{
height = ( cylinderHeight >= 0.0 ? cylinderHeight : 0.0 );
}

public double getHeight()
{
return height;
}

public double area()
{
return 2 * super.area() + 2 * Math.PI * radius * height;
}

public double volume()
{
return super.area() * height;
}

public String toString()
{
return super.toString() + "; height = " + height;
}

public String getName()
{
return "Cylinder:";
}
}


----------------解决方案--------------------------------------------------------
public class Cylinder3 extends Circle3
这不是继承了么!!!
----------------解决方案--------------------------------------------------------
你不是用了继承了吗!楼主下次不要这么发上来啊!眼睛看了吃不消啊!

[此贴子已经被作者于2006-12-6 23:17:11编辑过]



----------------解决方案--------------------------------------------------------
  相关解决方案