import java.util.* ; class A { A(int i1) { System.out.println( "A(): " + i1 ) ; } } class B { //Gets initialized after static A normalAObject = new A(1 ) ; //Static Gets initialized first. Either through //use of A or access the static object static A staticAObject = new A( 2 ) ; B() { //Gets initialized after data members initialization System.out.println( "B()" ) ; } } class Employee { int id; //class variables get initialized with //default values boolean b1; char c1; byte byte1; short short1; int int1; long long1; float float1; double double1; Employee employeeObject ; //Allowed to initizlize int int2 = 42 ; //Initialization is from top to bottom // int j1 = method2(i1); // Illegal forward reference int i1 = method1(); int method1() { System.out.println( "method1() getting called." ) ; return 10 ; } int method2(int x1) { return x1 * 2; } void printInitialValues() { System.out.println( "Data type Initial value"); System.out.println( "boolean " + b1 ); System.out.println( "char [" + c1 + "]" ); System.out.println( "byte " + byte1 ); System.out.println( "short " + short1 ); System.out.println( "int " + int1 ); System.out.println( "long " + long1 ); System.out.println( "float " + float1 ); System.out.println( "double " + double1 ); System.out.println("reference " + employeeObject ); } public Employee() { //Initialization can be done here //The initialization at the class data members will //be done firts. System.out.println( "Employee() constructor." ) ; } public void method1( float x1P ) { //method data members int i1 ; //Invalid. Won't let us use i1 unless it is initialized //System.out.println( i1 ) ; } //data members can be spread through out the class //and can come after the methods but will be initialized //before the methods. int i2 = method1(); } public class Initialization { public static void main( String args[] ) { Employee employeeObject = new Employee() ; employeeObject.printInitialValues() ; System.out.println( "We have not used A or B. " ) ; B BObject1 = new B() ; } //public static void main( String args[] ) }