我有两个文件,第一个是
Welcome.java
package com.project;
import com.code.*;
class Welcome {
public static void main(String[] args) {
Test t = new Test();
System.out.println("the valus is " + t.addition(4,3));
}
}
Test.java
package com.code;
public class Test {
private int a;
private int b;
public Test() {
a=2;
b=3;
}
public int addition(int a, int b) {
return a+b;
}
}
当我编译Welcome.java时,我得到了:
错误:找不到符号
System.out.println(" valus是" + t.addition(4,3));
找不到原因?请帮忙
编辑:
我用这个命令编译:
javac com/project/Welcome.java
解决方案:
javac -cp com/code/* com/project/Welcome.java
答案 0 :(得分:2)
在Test中,加法方法应该是public int addition(int a,int b)