Java OCA OCP Practice Question 945

Question

Which of the following can fill in the blank in this code to make it compile?

Choose all that apply

public class Main { 
  _____ void method() { } 
} 
A.   default 
B.   final 
C.   private 
D.   Public 
E.   String 
F.   myLabel: 


B, C.

Note

void is a return type.

Only the access modifier or optional specifiers are allowed before the return type.

Option C is correct, creating a method with private access.

Option B is correct, creating a method with default access and the optional specifier final.

Since default access does not require a modifier, we get to jump right to final.

Option A is incorrect because default access omits the access modifier rather than specifying default.

Option D is incorrect because Java is case sensitive.

It would have been correct if public were the choice.

Option E is incorrect because the method already has a void return type.

Option F is incorrect because labels are not allowed for methods.




PreviousNext

Related