What is Local Variable? Another of the most popular Java developer interview questions. A local variable is a variable that is defined within a method and exists until the method is executed. Once execution ends, the local variable will no longer exist. Here is a program that uses the local variable helloMessage in the main() method:
public static void main(String[] args) {
String helloMessage;
helloMessage = "Hello, World!";
System.out.println(helloMessage);</ span>
}