Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume that the following classes have been defined: public class George extends Elaine { public void method 1 ( ) { System.out.print ( George

Assume that the following classes have been defined:
public class George extends Elaine {
public void method1(){
System.out.print("George 1");
}
}
public class Jerry {
public void method1(){
System.out.print("Jerry 1");
}
public void method2(){
System.out.print("Jerry 2");
}
public String toString(){
return "Jerry";
}
}
public class Elaine extends Kramer {
public String toString(){
return "Elaine "+ super.toString();
}
}
public class Kramer extends Jerry {
public void method1(){
super.method1();
System.out.print("Kramer 1");
}
public void method2(){
System.out.print("Kramer 2");
method1();
}
public String toString(){
return "Kramer";
}
}
public class George extends Elaine {
public void method1(){
System.out.print("George 1");
}
}
public class Jerry {
public void method1(){
System.out.print("Jerry 1");
}
public void method2(){
System.out.print("Jerry 2");
}
public String toString(){
return "Jerry";
}
}
public class Elaine extends Kramer {
public String toString(){
return "Elaine "+ super.toString();
}
}
public class Kramer extends Jerry {
public void method1(){
super.method1();
System.out.print("Kramer 1");
}
public void method2(){
System.out.print("Kramer 2");
method1();
}
public String toString(){
return "Kramer";
}
}
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.)
Jerry[] seinfeld ={ new George(), new Kramer(), new Jerry(), new Elaine()};
for (int i =0; i < seinfeld.length; i++){
seinfeld[i].method1();
System.out.println();
seinfeld[i].method2();
System.out.println();
System.out.println(seinfeld[i]);
System.out.println();
}
Jerry[] seinfeld ={ new George(), new Kramer(), new Jerry(), new Elaine()};
for (int i =0; i < seinfeld.length; i++){
seinfeld[i].method1();
System.out.println();
seinfeld[i].method2();
System.out.println();
System.out.println(seinfeld[i]);
System.out.println();
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Evaluating Group Performance?

Answered: 1 week ago