Question: Consider the following class. public class Person (private String name; public Person(String name) { this.name = } name; @Override public String tostring() { return

Consider the following class. public class Person (private String name; public Person(String 

Consider the following class. public class Person (private String name; public Person(String name) { this.name = } name; @Override public String tostring() { return this.getClass().getName() + "[name=" + this.name + "]"; } } If we have a Person object whose attribute name is a reference to the String object "Alice", calling toString() on this object will return the String: "Person[name=Alice]" Now consider the following class. public class Customer extends Person { private int balance; } In your answer to the parts below, do not modify the class Person. You may only use the parts of the classes Person and Customer shown above. (a) Override the method public String toString() in the class Customer so that 5 marks it returns a String that contains the word "Customer", the name, and the balance. For example, calling toString!) on a Customer with name "Alice" and balance 1200 is supposed to return the following String: "Customer[name=Alice][balance=1200]" (b) Write two public constructors for the class Customer: 11 marks The first constructor has two parameters of types String and int with the name and the balance. It initialises the instance variables with the values of the corresponding parameters.

Step by Step Solution

3.48 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a To override the toString method in the Customer class youll need to call the supe... View full answer

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 Programming Questions!