+ 3
What is the purpose of (static) and (void) in java
guys I'm new to java so please explain it to me
7 Answers
+ 6
The module explains it really well, but basically static means that it belongs to the class, not to a specific object, and void means that it does not return any value. Read through the lesson a few more times and you will understand it better.
0
I don't know about static but void returns a value pack
0
If "void" is not mentioned then the value/string which has to be obtained as the output will not return any value!!!! So "void" is Required!!!
0
static is the primary keyword reserved which is read by the compiler before reading any other statement. it is executed before any other function present in the program
0
static is a key word. if a function is preceded by static key word, it can be called or accessed before any of the objects have been created. here objects correspond to the instances of the class to which the above said function belongs.
as far as void is concerned a function preceded by void key word does not return any sort of value to the calling module or OS (in case of main).
0
static keyword before a method , means that we doesn't need to create an object of a class to call that static method.Example : main() method we doesn't need to create an object to call main within a program. Therefore static methods can be called by only static data members/member functions( A non static data member cannot call a static member functions) also if a data member is said to be a static initialise with 0 then that data member can access a static member function "n" number of times, every n++ will share a common memory area, no separate memory is created for each call. Whereas in non static member we have a separate memory allocation for every call.
and void signifies that a function doesn't return anything, return type is mandatory.Also main can have different return types depending upon the content in it!