0
0
Javaprogramming~15 mins

Return values in Java - Cheat Sheet & Quick Revision

Choose your learning style8 modes available
overviewRecall & Review
beginner
What is a return value in Java?
A return value is the result a method sends back to the part of the program that called it. It lets the method give information after it finishes running.
touch_appClick to reveal answer
beginner
How do you specify the type of value a method returns in Java?
You write the type before the method name in its declaration. For example, int means the method returns an integer number.
touch_appClick to reveal answer
intermediate
What happens if a method has a return type other than void but does not use a return statement?
The program will not compile. Java requires that all paths in such a method return a value matching the declared type.
touch_appClick to reveal answer
intermediate
Can a method return multiple values directly in Java?
No, a method can return only one value. To return multiple values, you can use an object or an array to hold them.
touch_appClick to reveal answer
beginner
What does the void keyword mean in a method declaration?
It means the method does not return any value. It just runs its code and finishes without sending anything back.
touch_appClick to reveal answer
What keyword is used to send a value back from a method in Java?
Aoutput
Bsend
Creturn
Dyield
If a method is declared as int calculate(), what must it do?
AReturn an integer value
BReturn nothing
CReturn a string
DThrow an exception
What will happen if a method with return type double does not have a return statement?
ARuns without error
BCompilation error
CReturns null
DReturns 0.0 automatically
Which of these methods does NOT return a value?
Avoid printMessage()
Bint getNumber()
CString getName()
Ddouble calculateArea()
How can a method return multiple values in Java?
ABy calling return several times
BBy using multiple return statements
CBy declaring multiple return types
DBy returning an object or array containing the values
Explain what a return value is and why it is useful in Java methods.
Describe the difference between a method with a void return type and one with a specific return type.