OCA Java SE 8 Mock Exam Review - OCA Mock Question 1
Question
What happens if you try to compile and run the following code:
public class Main {
public static void main(String arguments[]) {
someMethod(arguments);
}
public void someMethod(String[] parameters) {
System.out.println(parameters);
}
}
- Compile error ? main is not declared correctly.
- Compile error ? the variable parameters cannot be used as it is in the
println method.
- Compile error ? someMethod is not declared as static and cannot be used in main method.
- The program will execute without errors.
Answer
Note
You cannot access an instance method from a static method.