Question: public class Person { / / Fields private String name; private boolean hasDriverLicense; private int age; private int height; / / Constructor public Person (
public class Person
Fields
private String name;
private boolean hasDriverLicense;
private int age;
private int height;
Constructor
public PersonString name, boolean hasDriverLicense, int age, int height
this.name name;
this.hasDriverLicense hasDriverLicense;
this.age age;
this.height height;
Getters
public String getName
return this.name;
public boolean hasDriverLicense
return hasDriverLicense;
public int getAge
return age;
public int getHeight
return height;
Clone method
public Person clone
Person newPerson new Personthisname, this.hasDriverLicense, this.age, this.height;
return newPerson;
Equals method
@Override
public boolean equalsObject o
if o null
return false;
if o this
return true;
ifo instanceof Person
Person person Person o;
ifpersongetNameequalsthisname
ifpersonhasDriverLicensethis.hasDriverLicense
ifpersongetAgethis.age
ifpersongetHeightthis.height
return true;
return false;
ToString method
@Override
public String toString
ifhasDriverLicense true
return String.formatPerson names aged heightd has licenses license
name, age, height;
return String.formatPerson names aged heightd no licenses license
name, age, height;
fix code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
