a. Show the output of the following program: 1: public class Test { 2: public static void main ( String [] args ) { 3: A a = new
A( 3 ); 4: } 5: } 6: 7: class A extends B { 8: public A ( int t ) { 9: System.out.println( "A's constructor is invoked" ); 10: } 11: } 12: 13: class B { 14: public B () { 15: System.out.println( "B's constructor is invoked" ); 16: } 17: } b. Is the no-arg constructor of Object invoked when new A(3) is invoked? 6. Indicate true or false for the follow statements: a. You can always successfully cast an instance of a subclass to a superclass. b. You can always successfully cast an instance of a superclass to a subclass. 7. What's wrong with the following code? 1: public class Test { 2: public static void main ( String [] args ) { 3: Object fruit = new Fruit(); 4: Object apple = (Apple) fruit; 5: } 6: } 7: 8: class Apple extends Fruit { 9: } 10: 11: class Fruit { 12: } 8. When overriding the equals method, a common mistake is mistyping its signature in the subclass. For example, the equals method is incorrectly written as equals (Circle circle) as shown in (a) below. It should be written as equals(Object circle), as shown in (b) below. Show the output of running class Test using the Circle class first from (a), and then from (b). Explain the output. 1: public class Test { 2: public static void main ( String [] args ) { 3: Object circle1 = new Circle(); 4: Object circle2 = new Circle(); 5: System.out.println( circle1.equals( circle2 ) );
Best way to store all your files is a external storage device, like a hard drive or a usb stick, copy all your files to the device and keep it in a safe place.