I am reviewing for a
test and have am not sure about a question(sure more to come later)
For the question(s) below, 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;
}
}
4) Consider that you want to extend AClass to BClass. BClass will have a third int instance data, z. Which of the following would best define BClass' constructor?
A) public BClass(int a, int b, int c)
{
super(a, b, c);
}
B) public BClass(int a, int b, int c)
{
x = a;
y = b;
z = c;
}
C) public BClass(int a, int b, int c)
{
z = c;
}
D) public BClass(int a, int b, int c)
{
super(a, b);
z = c;
}
E) public BClass(int a, int b, int c)
{
super( );
}
I think it is D but I could be wrong(probably am lol) I think this because of inheritance I figure since a,b don't change from A(well I think they don't) so why not call them from the superclass and then add the 3rd one.