For the questions below consider the following class definit

For the questions 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; } } 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? 1. public BClass(int a, int b, int c) { super( ); } 2. public BClass(int a, int b, int c) { z = c; } 3. public BClass(int a, int b, int c) { super(a, b, c); } 4. public BClass(int a, int b, int c) { super(a, b); z = c; } 5. public BClass(int a, int b, int c) { x = a; y = b; z = c; }

Solution

The best definition of B Class\'constructor is

public BClass(int a, int b, int c) {

super(a, b);

z = c;

}

So the answer is option (4)

For the questions below, consider the following class definition: public class AClass { protected int x; protected int y; public AClass(int a, int b) { x = a; y

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site