初学构造方法,一个java文件定义一个类,另外一个如何使用这个类,望知道
public class TestCircle1{
public static void main(String[] args){
Circle1 circle1=new Circle1();
System.out.println("The area of the circle of radius"+circle1.radius+" is "+circle1.getArea());
//Create a circle with radius 25
Circle1 circle2=new Circle1(25);
System.out.println("The area of the circle of radius"+circle2.radius+" is "+circle2.getArea());
Circle1 circle3=new Circle1(125);
System.out.println("The area of the circle of radius"+circle3.radius+" is "+circle2.getArea());
circle2.radius=100;
System.out.println("The area of the circle of radius"+circle2.radius+" is "+circle2.getArea());
}
}
class Circle1{
double radius;
Circle1(){
radius = 1.0;
}
Circle1(double newRadius){
radius=newRadius;
}
double getArea(){
return radius*radius*Math.PI;
}
}
如上,类Circle1 和类TestCircle1在同一个java文件里面,可以运行
我如果将Circle1的类单独建一个Circle1.java,TestCircle1也单独一个TestCircle1.java,然后javac TestCircle1.java,显示找不到找不到符号Circle1,这是什么原因了?
两个java?文件
------解决方案--------------------得先javac Circle1.java