0

Can static methods have return types?

27th Aug 2016, 2:52 AM
NOEL PHILIP
NOEL PHILIP - avatar
2 Answers
0
returning not depend on static or non-static it's depends on void static void sayHello() void sayHello() both above methods don't return a value static int sayHello() string sayHello() first method return int value and second one return string
30th Aug 2016, 3:03 PM
mehdi
0
yes. They must have one. static is a modifier. so a method syntax is: modifier returnType method_name(args_if_any) { } Eg: static int sum(int a, int b) { } void is also a return type only that doesn't return any value. if a method is not returning any value then void is used, so that the control can go to the next line for further execution. Hope it Helps😊
19th Sep 2016, 2:18 PM
Tanya
Tanya - avatar