Question: Consider the following class definition: public class AClass { protected int x; protected int y; public AClass (int a, int b) { x=a; y=b; }

Consider the following class definition:

public class AClass

{

protected int x;

protected int y;

public AClass (int a, int b)

{

x=a;

y=b;

}

public int addEm()

{

return x + y;

}

public void changeEm()

{

x++;

y--;

}

public String toString()

{

return + x + + y;

}

}

Write the BClass with the following specifications:

* BClass extends the AClass

* BClass will have a third int instance data, z

* A constructor for the BClass

* Override method addEm to all all 3 values and return the sum

* Override the toString method for the BClass

Note: The best way to redefine a method is to reuse the parent class' method and supplement it with the code needed to handle the changes in the subclass.

This is what I have:

public class BClass extends AClass

{

super.AClass();

public BClass()

{

int x=0;

int y=0;

int z=0;

}

public static addEm(int a, int b, int c)

{

int sum;

sum = a+b+c;

}

public static toString()

{

return null;

}

}

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