Basically, methods are blocks in our Java class. Let's write one block here as an example, and observe where the opened and closed brackets are placed. The following example shows one complete block:
public void getData()
{
static int a=4;
}
In this code, we have named the block of code getData() and void is the return type for this method.
If we are expecting to return a number from the method, and the number is an integer, then we have to write integer in place of void. The same applies with strings; if we are planning to return a string from the getData() method, then we have to declare it as a string. If we are not returning anything, that is, if we are simply writing a few lines of code, then we leave it as void.
Take a look at the following screenshot:
Here, we are not returning anything, so we...