Java OCA OCP Practice Question 1473

Question

What should be the return type of the following method?

public ___ methodX ( byte by){ 
    double d = 10.0; 
    return  (long) by/d*3; 
} 

Select 1 option

  • A. int
  • B. long
  • C. double
  • D. float
  • E. byte


Correct Option is  : C

Note

The cast (long) applies to 'by' not to the whole expression.

((long)by)/d*3; 

Division operation on long gives you a double.

So the return type should be double.




PreviousNext

Related