In Java, a method can be defined with a return type and without arguments. This means the method returns a value but does not take any input parameters.
β General Syntax:
returnType methodName() {
// method body
return value; // value must match returnType
}
In Java, methods can be categorized by whether they return a value and whether they accept arguments.
You’re asking for:
Java method with arguments but without return type
β 1. Definition:
These methods:
-
Accept arguments (parameters)
-
Do not return any value
-
Use the keyword
void
as return type -
β 2. Syntax Example:
public class Example {
// Method with arguments, no return type
void greetUser(String name) {
System.out.println(“Hello, ” + name + “!”);
}
public static void main(String[] args) {
Example obj = new Example();
obj.greetUser(“Bhagya”); // Calling method with argument
}
}
In Java, a method without a return type and without arguments is:
-
Declared using
void
(which means no return value) -
And it does not take any parameters inside the parentheses
()
β Syntax: