+ 1
I don't understand the "void" function and why a method should have it or why not have it?
7 Answers
+ 6
there are 2 types of method :
void
return
you cannot make a method without any of these types
+ 5
void means your method does not return any values. If your method does not have void, it must return something (int, String, double, etc.)
+ 4
When a method you defined does not have the "return" keyword, you use "void". However, if it does have the "return" keyword, you use the data type for the return value.
For integers, you use int
For strings, you use string
.
.
.
In summary, "void" means nothing is returned.
+ 1
We create functions. Some of them doesn't returns any value then how can we take it's return type. Here we need something which can restrict the use of return in my function, So 'void' is used when a function doesn't return anything.
+ 1
void doesnot return anything.
0
void means empty or zero. so we use it in methods in which values don't need to be returned