Question: inheritanceMystery 2 Language / Type: Java inheritance polymorphism Assume that the following classes have been defined: public class Brienne extends Oberyn { public void a

inheritanceMystery2
Language/Type: Java inheritance polymorphism
Assume that the following classes have been defined:
public class Brienne extends Oberyn {
public void a(){
System.out.print("Brienne-a ");
}
}
public class Arya {
public void a(){
System.out.print("Arya-a ");
}
public void b(){
a();
System.out.print("Arya-b ");
}
public String toString(){
return "Arya";
}
}
public class Tyrion extends Arya {
public void a(){
super.a();
System.out.print("Tyrion-a ");
}
}
public class Oberyn extends Arya {
public void b(){
System.out.print("Oberyn-b ");
super.b();
}
public String toString(){
return "Oberyn";
}
}
Given the classes above, what output is produced by the following code? (Since the code loops over the elements of an array of objects, write the output produced as the loop passes over each element of the array separately.)
Arya[] thrones ={ new Oberyn(), new Arya(), new Brienne(), new Tyrion()};
for (int i =0; i < thrones.length; i++){
thrones[i].a();
System.out.println();
System.out.println(thrones[i]);
thrones[i].b();
System.out.println();
System.out.println();
}

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!