Java: Method Return Value
Dec 11, 2023
Before we write a method using void. Void itself is a default that will return nothing from our method. So now, method has a way to return a value, a specific one that will make it useful in some cases.
public class Main {Get Aldyputu’s stories in your inbox
Join Medium for free to get updates from this writer.
/*
We declare that we want String output from our method, so we write it when
initialize the method return. Adding parameter based on what we need but,
make sure the output/return statement is String or any datatype that
we declare when create our method.
*/
static String getEmail(String firstName, String lastName){
var email = firstName + lastName + "@gmail.com";
return email;
}
public static void main(String[] args){
var a = "Joko";
var b = "Wiguna";
var c = getEmail(a,b);
System.out.println(c);
}
}




