请给我一个命名一个具有相同名称的类和构造函数的逻辑答案.为什么我们不能为构造函数选择除类名之外的其他名称?
class Temp
{
Temp()
{
}
};
Run Code Online (Sandbox Code Playgroud) 以下是代码,我写的是从用户那里得到两个输入.但是当我运行程序时,它只需要一个输入并自己生成另一个并计算错误的值.请帮忙.谢谢
import java.io.IOException;
import java.util.*;
class ThrowsExcpt {
int divide(int x, int y) throws ArithmeticException, IOException {
return x / y;
}
}
class ThrowsTemps {
public static void main(String s[]) throws IOException {
int x = System.in.read();
int y = System.in.read();
ThrowsExcpt th = new ThrowsExcpt();
int r = th.divide(x, y);
System.out.println(r);
}
}
Run Code Online (Sandbox Code Playgroud) java ×2