What is the point of return
Basically, from what I have read, return is supposed to store the value in memory. How are you supposed to access this value then? I wrote this code attempting to access the value but if the only way to access it is by declaring a variable, I don't see the point using return in the first place.. As for returns without a value you can use break.. So why bother with return statements at all? Below is the code I wrote. calling sum with 2 values alone doesn't output a value but im not interested in outputting it directly im interested in returning it and accessing it at a later point. class MyClass { static int sum(int val1, int val2) { return val1 + val2; } public int getsum(){ return sum; } public static void main(String[ ] args) { sum(2, 5); getsum(); } }