Using methods

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 ...

Get Hands-On Automation Testing with Java for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.