Question: public class C1 { public C1() { /* implementation not shown */ } public void m1() { System.out.print(A); } public void m2() { System.out.print(B); }

public class C1

{

public C1()

{ /* implementation not shown */ }

public void m1()

{ System.out.print("A"); }

public void m2()

{ System.out.print("B"); }

}

public class C2 extends C1

{

public C2()

{ /* implementation not shown */ }

public void m2()

{ System.out.print("C"); }

}

The following code segment appears in a class other than C1 or C2.

C1 obj1 = new C2();

obj1.m1();

obj1.m2();

The code segment is intended to produce the output AB. Which of the following best explains why the code segment does not produce the intended output?

  • A) compile-time error occurs because obj1 is declared as type C1 but instantiated as type C2.

  • B) A runtime error occurs because method m1 does not appear in C2.

  • C) Method m1 is not executed because it does not appear in C2.

  • D) Method m2 is executed from the subclass instead of the superclass because obj1 is instantiated as a C2 object.

  • E) Method m2 is executed twice (once in the subclass and once in the superclass) because it appears in both classes.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!