Initializing variables with initializers - Java Language Basics

Java examples for Language Basics:Variable

Introduction

An initializer, which has the following general form:

type name = expression;

The initializer lets you combine a declaration and an assignment statement into one concise statement.

Here are some examples:

Demo Code

public class Main {
  public static void main(String[] args) {
    int x = 0;/*from   w ww  .  ja v  a2 s .  co  m*/
    String lastName = "Lowe";
    double radius = 15.4;
    
    System.out.println(x);
    System.out.println(lastName);
    System.out.println(radius);
  }

}

Related Tutorials