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
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