【发布时间】:2016-03-03 04:28:16
【问题描述】:
我在 JAVA 中有两个用于函数重载的类,即 ABC 和 XYZ。 XYZ 类具有函数重载方法,而 ABC 类具有 main 方法。我已将文件保存为 ABC.java。该程序确实可以编译,但在运行时显示错误“无法找到或加载主类 ABC”。我还附上了具体的代码。
class XYZ
{
void pqr(int a, int b)
{
int res = a*b;
System.out.println("The result is "+res);
}
void pqr(String a, String b)
{
System.out.println("The concatenated string is "+a+b);
}
void pqr(int a, int b, int c)
{
int res = a+b+c;
System.out.println("The final result is "+res);
}
}
class ABC
{
public static void main(String[] args)
{
XYZ a = new XYZ();
a.pqr(10,20);
a.pqr("Pratik","Paul");
a.pqr(20, 40, 60);
}
}
【问题讨论】:
-
我认为没有错误
-
公开课程
ABC -
@Pratik:你能提到这些文件的文件夹路径吗?你还在用 eclipse 还是记事本工作?
-
@Lathy:这些文件的路径是 D:\Pratik\Java。目前我正在使用 notepad++ 并使用 javac 完成编译
-
@sandip:我做了,但出现了另一个错误,上面写着“ABC 类是公共的,应该在名为 ABC.java 的文件中声明”