[Solved]Question 5 Run Following Code New 1 B B New B 2 Systemprintln B Select Following Pieces Co Q37295253
QUESTION 5
-
If we run the following code:
A a = new A(1);
B b = new B(2);
System.out.println(b);Select all of the following pieces ofcode that would compile and run with no errors, printing the valueof 1 followed by the value of 2, each on separate lines.
A.
public class A {
private int y;public A(int y) {
this.y = y;
}public int getY() {
return y;
}public String toString() {
return “” + y;
}
}public class B extends A {
private int x;public B(int x) {
this.x = x;
}public String toString() {
return super.toString()+ “n” + x;}
}B.
public class A {
private int y;public A(int y) {
this.y = y;
}public int getY() {
return y;
}public String toString() {
return “” + y;
}
}public class B extends A {
private int x;public B(int x) {
this.x = x;
}public String toString() {
return “” + y + “n” +x;}
}C.
public class A {
protected int y;public A(int y) {
this.y = y;
}public int getY() {
return y;
}public String toString() {
return “” + y;
}
}public class B extends A {
private int x;public B(int x) {
this.x = x;
}public String toString() {
return “” + y + “n” +x;}
}D.
public class A {
private int y;public A(int y) {
this.y = y;
}public int getY() {
return y;
}public String toString() {
return “” + y;
}
}public class B extends A {
private int x;public B(int x) {
this.x = x;
}public String toString() {
return “” + x + “n” +super.toString();}
}E.
public class A {
private int y;public A(int y) {
this.y = y;
}public int getY() {
return y;
}public String toString() {
return “” + y;
}
}public class B extends A {
private int x;public B(int x) {
this.x = x;
}public String toString() {
return “” + getY() +”n” + x;}
}
QUESTION 6
-
Why did you choose the answer you did in Question 5? Explainyour thinking as clearly as possible.
Expert Answer
Answer to QUESTION 5 If we run the following code: A a = new A(1); B b = new B(2); System.out.println(b); Select all of the follow… . . .
OR

