Answered step by step
Verified Expert Solution
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) { } } |
- The program has a compile error, because m is overridden with a different signature in Z.
- The program has a compile error, because z.m(10) cannot be invoked since the method m(int) is hidden in Z.
- The program has a runtime error on z.i, because i is not accessible from z.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started