O'Reilly logo

Hands-On Automation Testing with Java for Beginners by Rahul Shetty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required