Assume that the following classes have been defined: public class A extends B {
ID: 3772558 • Letter: A
Question
Assume that the following classes have been defined:
public class A extends B {
public void method2() {
System.out.print("a 2 ");
method1();
}
}
public class B extends C {
public String toString() {
return "b";
}
public void method2() {
System.out.print("b 2 ");
super.method2();
}
}
public class C {
public String toString() {
return "c";
}
public void method1() {
System.out.print("c 1 ");
}
public void method2() {
System.out.print("c 2 ");
}
}
public class D extends B {
public void method1() {
System.out.print("d 1 ");
method2();
}
}
Given the classes above, what output is produced by the following code?
C[] elements = {new A(), new B(), new C(), new D()};
for (int i = 0; i < elements.length; i++){
System.out.println(elements[i].getClass());
System.out.print(elements[i].toString());
System.out.println();
elements[i].method1();
System.out.println();
elements[i].method2();
System.out.println();
System.out.println();
Explanation / Answer
This is the output u Get
b
c 1
a 2
b
c 1
b 2
c
c 1
c 2
b
d 1
b 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.