Java examples for Object Oriented Design:Class
Initializers are executed whenever an instance of a class is created, regardless of which constructor is used to create the instance.
Initializer blocks are similar to variable initializers used to initialize variables.
import java.util.Scanner; public class PrimeClass { private Scanner sc = new Scanner(System.in); public int x; {/*ww w .ja va2 s .c o m*/ System.out.print("Enter the starting value for x: "); x = sc.nextInt(); } }