This does not work
public String getjLabel4text(void){...
But this does
public String getjLabel4text(){...
Why so? I am not taking any arguments so shouldn't I write void there? Why is it causing an error?
This does not work
public String getjLabel4text(void){...
But this does
public String getjLabel4text(){...
Why so? I am not taking any arguments so shouldn't I write void there? Why is it causing an error?
More generally, method declarations have six components, in order:
Modifiers—such as public, private, etc.
The return type—the data type of the value returned by the method, or void if the method does not return a value.
The method name—the rules for field names apply to method names as well, but the convention is a little different.
The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.
An exception list—to be discussed later.
The method body, enclosed between braces—the method's code, including the declaration of local variables, goes here.
In C and C++ we can take void as an method argument because void is a datatype in both c and c++ . But Java is different, Here void is not a datatype rather its a keyword that is used just to signify method will not return any argument. so taking void as argument is technically invalid and is of no use, this () itself is sufficient.
Ex.
public String Name() { return "Hello";}
and
public String Name(void){ return "Hello";}
In C : Name() will take unspecified no of argument for unspecified type and Name(void) will take no argument.
In C++ : Both Name() and Name(void) will take no argument.
In Java : Name() will work while Name(void) will return compilation error.