Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions