Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Medium
Question 4
For the class Test, which options, if used to replace /*INSERT*/, will print "Hurrah! I passed..." on to the console? Select 2 options.
- public class Test {
- /*INSERT*/ {
- System.out.println("Hurrah! I passed...");
- }
- }
-
A
static public void Main(String [] args) -
B
protected static void main(String [] args) -
C
public static void main(String [] a) -
D
static public void main(String [] args) -
E
public void static main(String [] args) -
F
public void main(String [] args)
Reveal correct answers
Correct answers: C, D
Explanation
As System.out.println needs to be executed on executing the Test class, this means special main method should replace /*INSERT*/.
Special main method's name should be "main" (all characters in lower case), should be static, should have public access specifier and it accepts argument of String [] type. String [] argument can use any identifier name, even though in most of the cases you will see "args" is used.
Position of static and public can be changed but return type must come just before the method name.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
