Page 1 of 1

About QID enthuware.ocajp.i.v8.2.828

Posted: Sun Jan 08, 2017 12:55 pm
by bniky1
There is a question about what line is invalid. According to the answer it is 3 and 4. Why isn't line 2 wrong?? I even tried manually and it failed to compile.

class Test{ }  // 1
public class TestClass {    
public int main(String[] args)  { // 2        
double x=10, double y;  // 3        
System.out.println[]; // 4                 
for(int k =0; k<x; k++){ } //5                 
return 0;    
}
}

This is for Java oca SE8.

Re: About QID enthuware.ocajp.i.v8.2.828

Posted: Sun Jan 08, 2017 7:15 pm
by admin
What do you think is wrong with //2?
Please post the exact code that failed to compile.

Re: About QID enthuware.ocajp.i.v8.2.828

Posted: Sun Jan 08, 2017 8:35 pm
by bniky1
Error: Main method is not static in class TestClass, please define the main method as:
public static void main(String[] args)

Re: About QID enthuware.ocajp.i.v8.2.828

Posted: Sun Jan 08, 2017 8:49 pm
by admin
This is not a compilation error. This is an error at run time and the error message is quite clear about what is the issue. It is looking for the standard main method. This doesn't mean that the main method that the class has is invalid. It just means that java cannot use that method to execute the class from command line.