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 ?

  1. y = 0

  2. super (0);

    y = 0;

  3. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!