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

Question 4-3 Fix the following program to produce the output. You SHOULD NOT CHA

ID: 3876347 • Letter: Q

Question

Question 4-3 Fix the following program to produce the output. You SHOULD NOT CHANGE/ADD any statement in the MAIN method. AND explain why this program is not working at this moment, and how you fixed the errors in DETAIL at the bottom of the program. class A5 s B5 extends A5( int i-2; class C5 extends B5t int i-3; public String y)(return "C.y": public class PolymorphismWhy5 f // output public static void main (String [] args) // Do not change/add this main method AS obj = new C5(); n (obj.i); /* Explain why and how in detail here

Explanation / Answer

This program is not working out because of a number of reasons. First, there is no function as x(). Second, here obj is of type A5 where variable i isn't defined and nor is method y() or x().

The correct code to get the desired output:

public class PolymorphismWhy5

{

public static void main (String[] args) throws java.lang.Exception

{

// your code goes here

A5 obj= new C5();

System.out.println(obj.i);

System.out.println(obj.x());

System.out.println(obj.y());

}

}

class A5{

int i = 1;

public String x()

{

return "A.x";

}

public void y(){}

}

class B5 extends A5{

int i =2;

}

class C5 extends B5{

int i=3;

public String y()

{

return "c.y";

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote