+ 1

what is the use of return key in java

24th Jul 2019, 8:09 AM
Abhimanyu Goswami
Abhimanyu Goswami - avatar
5 odpowiedzi
+ 15
In simple words return keyword simple returns a value from a method. retutn values ​​can be of many types. for example int float double byte char String Object arrays ListOfObjects like ArrayList, LinkedList.
24th Jul 2019, 9:57 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 4
Return is a reserved keyword in Java i.e, we can’t use it as an identifier. It is used to exit from a method, with or without a value. Tons of examples here: https://www.geeksforgeeks.org/return-keyword-java/
24th Jul 2019, 8:36 AM
m.b
m.b - avatar
+ 4
Say you call a method from main add(5,10); the add() method will take these arguments and add them together and "return" a value back to the calling method. int x = add(5,10); once this method is called adds the numbers together and "returns" a value it will look like this. int x = 15;
24th Jul 2019, 9:51 AM
D_Stark
D_Stark - avatar
+ 2
The return key takes you to a new line when editing code 😀
24th Jul 2019, 11:58 AM
Sonic
Sonic - avatar
0
it send result value of method to method which was calling it public class Program { public static void main(String[] args) { System.out.println("sum(10,5) returns "+sum(10,5) ); } static int sum(int a, int b) { return a + b; } }
24th Jul 2019, 9:51 AM
zemiak