How to Create a Variable and Assign Value Later in Java


In this example we will show you how to create a variable without assigning the value, and assign the value later in Java.

Source Code

package com.beginner.examples;

public class CreateAVariable {
  public static void main(String[] args) {
    int i; // create a variable
    i = 12; //assign the value
    System.out.println(i);
  }
}

Output:

12
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments