class A { public static int a = 1, b = 2; public int x = 5; public A( int x ) { System.out.println( "Invoke A( " + x + " )" ); this.x = x; } public A() { System.out.println( "Invoke A()" ); a++; x++; } public String toString() { return "A.toString(): " + x; } public void set( int x ) { this.x = x; } public int get() { return x; } public String f( int i ) { return "A.f( " + i + " )"; } public String f( double x ) { return "A.f( " + x + " )"; } } class B extends A { public static int a = 3, d = 4; public int x = 100; public B( int x ) { System.out.println( "Invoke B( " + x + " )" ); d++; this.x = x; } public void set( int x ) { this.x = x; } public int get() { return x; } public String f( char c ) { return "B.f( '" + c + "' )"; } public String f( double x ) { return "B.f( " + x + " )"; } } public class Main { public static void main( String[] args ) { A a1 = new A( 55 ); A a2 = new A(); B b1 = new B( 66 ); A b2 = b1; System.out.println( "A.a = " + A.a ); System.out.println( "A.b = " + A.b ); System.out.println( "B.a = " + B.a ); System.out.println( "B.d = " + B.d ); System.out.println(); System.out.println( "a1.x = " + a1.x ); System.out.println( "a2.x = " + a2.x ); System.out.println( "b1.x = " + b1.x ); System.out.println( "b2.x = " + b2.x ); System.out.println(); System.out.println( "a1 = " + a1 ); System.out.println( "a2 = " + a2 ); System.out.println( "b1 = " + b1 ); System.out.println( "b2 = " + b2 ); System.out.println(); // 'A' is ASCII 65 System.out.println( "a1.f( 'A' ) = " + a1.f( 'A' ) ); System.out.println( "b1.f( 'A' ) = " + b1.f( 'A' ) ); System.out.println( "b2.f( 'A' ) = " + b2.f( 'A' ) ); System.out.println(); System.out.println( "a1.f( 65 ) = " + a1.f( 65 ) ); System.out.println( "b1.f( 65 ) = " + b1.f( 65 ) ); System.out.println( "b2.f( 65 ) = " + b2.f( 65 ) ); System.out.println(); System.out.println( "a1.f( 65.0 ) = " + a1.f( 65.0 ) ); System.out.println( "b1.f( 65.0 ) = " + b1.f( 65.0 ) ); System.out.println( "b2.f( 65.0 ) = " + b2.f( 65.0 ) ); System.out.println(); b1.set( 123 ); b2.set( 456 ); System.out.println( "b1.x = " + b1.x ); System.out.println( "b2.x = " + b2.x ); System.out.println( "b1.get() = " + b1.get() ); System.out.println( "b2.get() = " + b2.get() ); } }