我不能理解:为什么会先调用了Test1 中的circle1 后不是直接调用circle2 而是是去调用了后面的System中的circle1.area() 和 circle2.area(); 然后再调用circle2中的各项,另外:为什么在Point1的构造函数中的System.out.println此句显示不出来?
import c.czg.Circle1;
public class Test1
{
public static void main ( String args[] )
{
Circle1 circle1,circle2;
circle1 = new Circle1 ( 4.5,72,29 );
circle2 = new Circle1 ( 10,5,5 );
System.out.println ( "The Circle1's area is :" + circle1.area() );
System.out.println ( "The Circle2's area is :" + circle2.area() );
circle1 = null;
circle2 = null;
System.gc();
}
}
另外一个是:
package c.czg;
import c.czg.Point1;
public class Circle1 extends Point1
{
protected double radius;
public Circle1()
{
radius = 0;
System.out.println ( "Circle3 constructor:" + this );
}
public Circle1 ( double circleRadius,int xCoordinate,int yCoordinate )
{
super( xCoordinate,yCoordinate );
radius = circleRadius;
System.out.println ( "Circle4 constructor:" + this );
}
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;
}
protected void finalize()
{
System.out.println ( "Circle5 finalizer:" + this );
super.finalize();
}
public String toString()
{
return " Center = " + super.toString() +
"; Radius = " + radius;
}
}
package c.czg;
public class Point1 extends Object {
protected int x,y;
public Point1()
{
x = 0 ;
y = 0 ;
System.out.println( "point0 constructor:" + this );
}
public Point1 ( int xCoording ,int yCoording )
{
x = xCoording ;
y = yCoording ;
System.out.println ( "Point1 constructor:" + this );
}
protected void finalize()
{
System.out.println ( "Point2 finalizer: " + this );
}
public String toString()
{
return "[" + x + "," + y + "]" ;
}
}