Java Return Type





 The return type in java refers to the data type of the value that a method returns. We can divide two types of return types and nonreturn types. the type of return requirements depends on the scenario.

The case where no return is expected.

If no return is expected from the method should be written as a void before the method name. it informs that no return is expected.


No alt text provided for this image
(0.1)

thus, since the main method has also been used to write the void, it is felt that no return is expected from the main method.

No alt text provided for this image
(0.2)

The case where the return is expected

Here it is essential to specify the data type before the method name instead of void. here, the data type to be returned is determined according to the date type provided. that is, when specified as int, double, char, or String the return is always the same as that data type.

int

No alt text provided for this image
(0.3)

double

No alt text provided for this image
(0.4)

Comments

Popular posts from this blog

Java Object-Oriented Programming