What is the proper way to defined a method that take two int values and returns their sum as an int value?

What is the proper way to defined a method that take two int values and returns their sum as an int
value?

What is the proper way to defined a method that take two int values and returns their sum as an int
value?

A.
int sum(int first, int second) { first + second; }

B.
int sum(int first, second) { return first + second; }

C.
sum(int first, int second) { return first + second; }

D.
int sum(int first, int second) { return first + second; }

E.
void sum (int first, int second) { return first + second; }



Leave a Reply 2

Your email address will not be published. Required fields are marked *


Hans

Hans

A. No return in body
B Second shoild be defined as int
C OK
D No return type in method signature
E void is no return

Hans

Hans

Sorry messed up C and D. D is the right answer.