Question: Consider the following class definition: public class AppleClass { private int x; private int y; public AppleClass(int a, int b) { x = a; y
Consider the following class definition: public class AppleClass { private int x; private int y; public AppleClass(int a, int b) { x = a; y = b; } public int addNum( ) { return x + y; } public void changeNum( ) { x++; y--; } public String toString( ) { return + x + + y; } } You have extended AppleClass to BanannaClass. BanannaClass has a third int instance variable, z. You want addNum to now add all three values and return the sum and changeNum to change x and y, but leave z alone. Which should you do?
Redefine addNum and changeNum without referencing super.addNum( ) or super.changeNum( ).
Redefine addNum to return the value of z + super.addNum( ), but leave changeNum alone.
Redefine changeNum to call super.changeNum( ) and then set z = x + y, but leave addNum alone.
Redefine addNum to return the value of z + super.addNum( ) and redefine changeNum to call super.changeNum( ) and then set z = x + y.
Redefine changeNum to call super.changeNum( ) without doing anything to z, and redefine addNum to return super.addNum( ).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
