0
Can static methods have return types?
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
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đ