OCA Java SE 8 Mock Exam Review - OCA Mock Question 35








Question

Which of the following methods correctly accepts three whole numbers as method arguments and returns their sum as a decimal number?

    a  public void addNumbers(byte arg1, int arg2, int arg3) { 
           double sum = arg1 + arg2 + arg3; 
        } 

    b  public double aMethod(byte arg1, int arg2, int arg3) { 
           double sum = arg1 + arg2 + arg3; 
           return sum; 
       } 

    c  public double numbers(long arg1, byte arg2, double arg3) { 
           return arg1 + arg2 + arg3; 
        } 

    d  public float bMethod(long a1, long a2, short a977) { 
           double sum = a1 + a2 + a977; 
           return (float)sum; 
       } 




Answer



B, D

Note

A is incorrect. The method does not return a decimal number with type double or float.

B is correct.

C is incorrect. This method doesn't accept integers as the method arguments. The type of the method argument arg3 is double, which isn't an integer.

D is correct.