Question: Three classes are defined as below. public class Person{ private String name; public Person(String n) { name = n; } public String toString() { return

Three classes are defined as below.

public class Person{ private String name; public Person(String n) { name = n; } public String toString() { return name; } } public class Senator extends Person{ private String party; public Senator(String n, String p){ super(n); party = p; } public String toString(){ String init = " (" + party.substring(0,1) +")"; return "Sen. " + super.toString() + init; } } class SenateLeader extends Senator{ private boolean majority; public Senator(String n, String p, boolean m){ super(n, p); majority = m; } } 

The following code segment appears in method in a separate class.

Person a = new Senator(Fred Harris, Democratic); Senator b = new Senator(Margaret Smith, Republican); Person c = new SenateLeader(Robert Griffin, Republican, false); System.out.println(a + ,  + b + ,  + c);

Which of the following will be printed as a result of executing this code segment?

Sen. Fred Harris (D), Sen. Margaret Smith (R), Robert Griffin

Fred Harris, Sen. Margaret Smith (R), Robert Griffin

Nothing is printed: an error occurs because there is no toString method declared in the SenateLeader class.

Sen. Fred Harris (D), Sen. Margaret Smith (R), Sen. Robert Griffin (R)

Fred Harris, Margaret Smith, Robert Griffin

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!