I have two classes for function overloading in JAVA namely ABC and XYZ. XYZ class has the function overloading methods whereas ABC class has the main method. I have saved the file as ABC.java. The program do compiles but shows an error "could not find or load main class ABC" during runtime. I have also attached my code to be specific.
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);
}
}
Follow the below steps,
Step1:
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
Step2:
javac <your ABC.java file with full path>
ex: javac C:\Test\ABC.java
similary do for XYZ.java
Step3:
Go to C:\Test\ from command prompt and run,
java ABC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.