OCA Java SE 8 Method - OCA Mock Question Method 20


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

public class Ant { 
    _____ void method() { } 
  1. default
  2. final
  3. private
  4. Public
  5. String
  6. zzz:


B, C.


void is a return type.

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

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

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

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

Option D is incorrect because Java is case sensitive.

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

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