0

Why does it say that main will not return a value beacuse it has void, yet it does return the value of 7?

4th Jul 2020, 7:29 PM
Don
4 odpowiedzi
+ 1
Oh god! I just realized that this chat room might not be linked to the lesson i'm in. So very sorry!
4th Jul 2020, 8:06 PM
Don
0
Thanks a bunch in advance! class MyClass { static int sum(int val1, int val2) { return val1 + val2; } public static void main(String[ ] args) { int x = sum(2, 5); System.out.println(x); } } Return: 7
4th Jul 2020, 7:44 PM
Don
0
In the second block of code, i see void right before main. Isnt that whole block printing out the returned value? What am i not getting?
4th Jul 2020, 7:46 PM
Don
0
From what i understand, 7 hasnt been assigned to anythin yet. Right? The last part says that one can assign it to something. The method named sum is of type int, and has 2 parameters of also type int, which will print another int. Yet the line of code system.out.println is within the block of code where main is, and i see void right before main. Im gonna try your statement though. Thanks a bunch again. Im still tryin to understand this. All help is very welcome😊
4th Jul 2020, 8:04 PM
Don