Java OCA OCP Practice Question 1164

Question

Which of the following can fill in the blank to make the class compile?

package ai; 
public class Main { 
      compute() { return 10; } 
} 
  • A. Public int
  • B. Long
  • C. void
  • D. private String


B.

Note

Option A is incorrect because the public access modifier starts with a lowercase letter.

Options C and D are incorrect because the return types, void and String, are incompatible with the method body that returns an integer value of 10.

Option B is correct and has package-private access.

It uses a return type of Long that the integer value of 10 can be easily assigned to without an explicit cast.




PreviousNext

Related