Question: Analyze the following code: public class Test { public static void main(String[] args) { Z z = new Z(); z.m(10); System.out.println(i is + z.i);

Analyze the following code:

public class Test {

public static void main(String[] args) {

Z z = new Z(); z.m(10); System.out.println(\"i is \" + z.i);

} }

-------------ANOTHER FILE------------------------- public class A {

int i;

public void m(int i) { this.i = i;

} }

-------------ANOTHER FILE------------------------- public class Z extends A {

public void m(String s) {

} }

  1. The program has a compile error, because m is overridden with a different signature in Z.
  2. The program has a compile error, because z.m(10) cannot be invoked since the method m(int) is hidden in Z.
  3. The program has a runtime error on z.i, because i is not accessible from z.
  4. The method m is not overridden in Z. Z inherits the method m from A and

defines an overloaded method m in Z.

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 Programming Questions!