Question: Consider the following class declarations. public class A { private int x; public A() { x = 0; } public A(int y) { x =
Consider the following class declarations.
public class A
{
private int x;
public A()
{ x = 0; }
public A(int y)
{ x = y; }
// There may be instance variables, constructors, and methods that are not shown.
}
public class B extends A
{
private int y;
public B()
{
/* missing code */
}
// There may be instance variables, constructors, and methods that are not shown.
}
Which of the following can be used to replace /* missing code */ so that the statement
B temp = new B();
will construct an object of type B and initialize both x and y with 0 ?
-
y = 0
-
super (0);
y = 0;
-
x = 0;
y = 0;
A. 1 only
B. 2 only
C. 1 and 2
D. 2 and 3
E. 1, 2, and 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
