Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Test { public static void main(String[ ] args) { B b = new B(); b.m

ID: 3610859 • Letter: P

Question

public class Test {

public static void main(String[ ] args) {

B b = new B(); b.m(5);

System.out.println("i is " + b.i);

   }

}

class A {

int i;

public void m(int i) {

this.i = i;

   }

}

class B extends A {

public void m(String s) {

}

}

A) The method m is not overridden in B. B inherits the method mfrom A and defines an overloaded method m in B.

B) The program has a compilation error, because m is overriddenwith a different signature in B.

C) The program has a runtime error on b.i, because i is notaccessible from b.

D) The program has a compilation error, because b.m(5) cannot beinvoked since the method m(int) is hidden in B.

2. Given the following classes and their objects:

class C1 {};

class C2 extends C1 {};

class C3 extends C1 {};

C2 c2 = new C2();

C3 c3 = new C3();

A) The statement is correct.

B) You will get a runtime error because you cannot cast objectsfrom sibling classes.

C) c3 is cast into c2 successfully.

D) You will get a runtime error because the Java runtime systemcannot perform multiple casting in nested form.

3. Analyze the following code:

public class Test {

public static void main(String[ ] args) {

String s = new String("Welcome to Java");

Object o = s;

String d = (String)o;

   }

}

A) S, O, and d reference the same Stringobject.

B) When assigning S to O inObject O = S , a new object is created.

C) When casting O to S in Stringd = (String)O , a new object is created.

D) When casting O to S in Stringd = (String)O, the contents of O is changed.

Explanation / Answer

1.A because the method doesn't contain the same signature it meansthat it is overloaded because the two arguments or parameters aredifferent one takes int and other takes a string. A 2.A 3. It is A or D not certain