Convert persons and patients to string

Report a typo

Here are two classes Person and Patient. The second class extends the first one.

Override toString in both classes to return a string representation of persons and patients.

If an object is Person, the overridden method toString must return something like:

Person{name=Case Maxwell,age=30}

If an object is Patient, the overridden method toString must return something like:

Patient{name=John Purcell,age=30,height=182}
Write a program in Java 17
class Person {

protected String name;
protected int age;

public Person(String name, int age) {
this.name = name;
this.age = age;
}
}

class Patient extends Person {

protected int height;

public Patient(String name, int age, int height) {
super(name, age);
this.height = height;
}
}
___

Create a free account to access the full topic