Card 45 / 76: Which of the following statements is/are true about declaring a return type? (Choose all that apply.)
A)
The keyword void is used to signify that a method does not return any value.
B)
The use of the keyword void is optional if the method isn’t returning anything.
C)
If a method is returning an int, it must declare this by having int precede the method name in the method signature.
D)
If the return type is omitted, a method may or may not return data, depending on the condition inside of the method.
Answer:
A) The keyword void is used to signify that a method does not return any value.
C) If a method is returning an int, it must declare this by having int precede the method name in the method signature.
Previous Card | ← Previous Card Button |
Next Card | → Next Card Button |
Flip Card | Space-Bar |
A is correct because the void keyword means the method will not return any data.
C is correct because the data type of the variable to be returned must precede the method name.
B and D are incorrect.
B is incorrect because void is not optional if the method isn’t returning anything. The void keyword must be included in this condition.
D is incorrect because a method must always declare a return type or void. If it is a constructor, it can omit a return type and it will be implied as void.
|