In this tutorial, we will discuss The void keyword in java programming language
The void keyword is a Java keyword. This keyword allows us to create methods which do not return a value. Which means void is a special type of keyword in Java as a void keyword does not return value unlike int, double, float etc at method declaration.
Syntax of the void keyword
return _type method_name(){ //statement(s) }
Example of a void method
void add(){ //statement(s) }
Above method is a void method as it does not return any value to the main method.
public class Example _void{ // this is a class in java public static void main(String args[]){ } public void add(){ // this is a void method. It does not produce return value; } }
Program 1
public class voidEx{ public static void main (String args[]){ my_age(50); } static void my_age(int age){ System.out.println("My age is :"+age); //No return } }
When the above code is executed, it produces the following results
The age is :50
In the above example, The method my_age is a void method passed as a parameter age(int) which does not return any value
There are other Java language keywords that are similar to this keyword
Suggested for you
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…