Given:
1. public class Pass2 {
2. public void main(String[] args) {
3. int x = 6;
4. Pass2 p = new Pass2();
5. p.doStuff(x);
6. System.out.print(” main x = ” + x);
7. }
8.
9. void doStuff(int x) {
10. System.out.print(” doStuff x = ” + x++);
11. }
12. }
And the command-line invocations:
javac Pass2.java
java Pass2 5
What is the result?
A.
Compilation fails.
B.
An exception is thrown at runtime.
C.
doStuff x = 6 main x = 6
D.
doStuff x = 6 main x = 7
E.
doStuff x = 7 main x = 6
F.
doStuff x = 7 main x = 7
Explanation:
The program compiled successfully, but main class was not found.
Main class should contain method: public static void main (String[] args).
C
B.
explanation…
there is no static keyword in main method