当前位置: 代码迷 >> Java面试 >> 初学者技术有关问题
  详细解决方案

初学者技术有关问题

热度:73   发布时间:2016-04-17 19:28:04.0
菜鸟技术问题
class Point{
private double x;
private double y;
Point ( double x1, double y1 ){
x = x1;
y = y1;
}
public double getX(){ return x;}
public double getY(){ return y;}
public void setX( double i ){ x = i; }
public void setY( double i ){ y = i; }

}
class Circle{
private Point o;//复用
private double radius;
Circle (Point p, double r){
o = p;
radius = r;
}
/*圆心定在原点上*/
Circle (double r){
o = new Point( 0.0,0.0);//圆心定在原点
radius = r;
} //重载
boolean contains(Point p){
double x = p.getX() - o.getX();
double y = p.getY() - o.getY();
if ( x*x + y*y > radius*radius) return false;
else return true;
}
public void setO( double x, double y){
o.setX(x);
o.setY(y);

}
public Point getO(){ return o;}
public double getRadius(){return radius;}
public void setRadius(double r) {radius = r;}
public double area(){
return 3.14 * radius * radius;
}
}
public class TestCircle{
public static void main(String[] args){
Circle c1 = new Circle(new Point(1.0,2.0),2.0);
Circle c2 = new Circle(5.0);
System.out.println("c1:("+c1.getO().getX()+","+c1.getO.getY()+"),"+c1.getRadius());
System.out.println("c2:("+c2.getO().getX()+","+c2.getO.getY()+"),"+c2.getRadius());
System.out.println("c1 Area is " +c1.area());
System.out.println("c2 Area is " +c2.area());
c1.setO(5,6);
c2.setRadius(9.0);
System.out.println("c1:("+c1.getO().getX()+","+c1.getO().getY()+"),"+c1.getRadius());
System.out.println("c2:("+c2.getO().getX()+","+c2.getO().getY()+"),"+c2.getRadius());
System.out.println("c1 area = " +c1.area());
System.out.println("c2 area = " +c2.area());
Point p1 = new Point(5.2, 6.3);
System.out.println(c1.contains(p1));
System.out.println(c1.contains(new Point(10.0, 9.0))); 
}
}
结果


D:\java1>javac TestCircle.java
TestCircle.java:48: 找不到符号
符号: 变量 getO
位置: 类 Circle
  System.out.println("c1:("+c1.getO().getX()+","+c1.getO.g
etY()+"),"+c1.getRadius());
  ^
TestCircle.java:49: 找不到符号
符号: 变量 getO
位置: 类 Circle
  System.out.println("c2:("+c2.getO().getX()+","+c2.getO.g
etY()+"),"+c2.getRadius());
  ^
2 错误

D:\java1>




请问怎么回事啊 我已经定义方法了!

------解决方案--------------------
在Circle 和Point 类前面加 static 必须是静态的才行
static class Circle 
static class Point
  相关解决方案