Example of Using an Instance Initializer - Java Object Oriented Design

Java examples for Object Oriented Design:Field

Description

Example of Using an Instance Initializer

Demo Code

public class Main {
  {/* w  ww.j  a v a2  s. c o  m*/
    System.out.println("Inside instance initializer 1.");
  }

  {
    System.out.println("Inside instance initializer 2.");
  }

  public Main() {
    System.out.println("Inside no-args constructor.");
  }

  public static void main(String[] args) {
    Main ii = new Main();    
  }
}

Result


Related Tutorials