Overriding deals with two methods one in a parent class and one in a child

Overriding deals with two methods one in a parent

This preview shows page 24 - 29 out of 35 pages.

Overriding deals with two methods, one in a parent class and one in a child class, that have the same signature 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;}} 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( );} Answer: d.
Image of page 24
Which of the following would best redefine the toString method for BClass?
Image of page 25