Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

discuss ways of measuring sickness absence and sickness presence;

Answered: 1 week ago

Question

What is a make-or-buy decision?

Answered: 1 week ago