June 2018
Beginner
722 pages
18h 47m
English
We could create a base class, Person, that has only the two fields age and name and the equals() method, as implemented previously. Then, we could extend it with the PersonWithHair class (which has the additional field hairstyle):
class Person{ private int age; private String name; public Person(int age, String name) { this.age = age; this.name = name; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Person person = (Person) o; return age == person.age && Objects.equals(name, person.name); }}class PersonWithHair extends Person{ private String hairstyle; public PersonWithHair(int age, String name, String ...
Read now
Unlock full access