我使用 dr java for linux 来运行我的代码。我最近在运行这个简单的程序时遇到了一堆错误。代码编译得很好,但是每当我运行 java 文件时,我都会收到错误消息;静态错误:未定义的名称这是我的代码;(我有两个文件,Square.java 和 SquareD.java)这里是 Square.java
public class Square{
private String name;
private int y;
private int x;
public Square(String st,int x2,int y2){
name=st;
x=x2;
y=y2;
}
public int square(){
return x*x+y*y;
}
double a1=(double) x;
double a2=(double) y;
public double hypotenuse(double a1,double a2){
double sum = a1*a1+a2*a2;
return Math.sqrt(sum);
}
public int area(){
return x*y;
}
public String getName(){
return name;
}
}
这是 SquareD.java;
public class Square{
private String name;
private int y;
private int x;
public Square(String st,int x2,int y2){
name=st;
x=x2;
y=y2;
}
public int square(){
return x*x+y*y;
}
double a1=(double) x;
double a2=(double) y;
public double hypotenuse(double a1,double a2){
double sum = a1*a1+a2*a2;
return Math.sqrt(sum);
}
public int area(){
return x*y;
}
public String getName(){
return name;
}
}
无论我在交互窗口中键入java Square.java
还是java SquareD.java
在交互窗口中,我都会得到,
静态错误:未定义的名称
我正在运行 Ubuntu 11.10