我想知道如何在 java 中的一个文件中使用多个类。我输入了这段代码,但它显示编译错误。
class test {
int a, b, c;
void getdata(int x, int y) {
a = x;
b = y;
}
void add() {
c = a + b;
System.out.println("Addition = " + c);
}
}
public class P8 {
public static void main(String[] args) {
test obj = new test();
test.getdata(200, 100);
test.add();
}
}
Run Code Online (Sandbox Code Playgroud) java ×1