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.
About QID enthuware.ocajp.i.v8.2.828
Moderator: admin
-
- Posts: 4
- Joined: Sun Jan 08, 2017 12:27 pm
- Contact:
-
- Site Admin
- Posts: 10074
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About QID enthuware.ocajp.i.v8.2.828
What do you think is wrong with //2?
Please post the exact code that failed to compile.
Please post the exact code that failed to compile.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Sun Jan 08, 2017 12:27 pm
- Contact:
Re: About QID enthuware.ocajp.i.v8.2.828
Error: Main method is not static in class TestClass, please define the main method as:
public static void main(String[] args)
public static void main(String[] args)
-
- Site Admin
- Posts: 10074
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About QID enthuware.ocajp.i.v8.2.828
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 12 guests