我在JAVA中有两个用于函数重载的类,即ABC和XYZ。 XYZ类具有函数重载方法,而ABC类具有主要方法。我已将文件保存为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);
}
}
答案 0 :(得分:0)
按照以下步骤
步骤1:
go the bin folder of Java from command prompt(I assume you are trying to run the program from command prompt).
ex: C:\Program Files\Java\jdk1.8.0_05\bin
步骤2:
javac <your ABC.java file with full path>
ex: javac C:\Test\ABC.java
similary do for XYZ.java
步骤3:
Go to C:\Test\ from command prompt and run,
java ABC