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
The boolean keyword in java
Suggested for you
Keywords in Java language
Keywords in C++ language
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…