0

Program In Java: I wrote a program written in java and tried to compile in command prompt (which succeeded) however an attempt to run the program failed (via command prompt as well as eclipse ).

package jenkov;

public class CheckProg {

public int math(int i) {
    try {
        int result = i / 0;
        // throw new IOException("in here");
    }
    catch (Exception e) {
        return 10;
    } 
    finally {
        return 11;
    }
}

public static void main(String[] args) {
    CheckProg c1 = new CheckProg();
    int res = c1.math(10);
    System.out.println("Output :" + res);
}
}
enter code here

Error Observed : Could not find or load main class

sudeept
  • 11
  • 1
  • 7
  • this is correct.. output should be 11 – spandey Feb 21 '18 at 11:24
  • 1
    You can find a very good explanation here: https://stackoverflow.com/a/18093929/3790546 – Pablo Feb 21 '18 at 11:31
  • Tried from Command Prompt a same program placed at a fresh location, ouptut reicieved 11. However when the same program is run from Eclipse IDE, output is Error: Could not find or load main class – sudeept Feb 21 '18 at 11:37
  • You'll need to add some insights on your Eclipse setup then. Are you able to launch other programs from Eclipse, HelloWorld for example? – Zabuzard Feb 21 '18 at 12:11
  • yes, other programs are running successfully from Eclipse – sudeept Feb 21 '18 at 12:30

0 Answers0