abstract class Ancestor { //To count the family members of this Ancestor with givenColor eyes abstract int withColor(String givenColor); } class Unknown extends Ancestor { Unknown() { } //new Unknown().withColor("green") == 0 //To count the family members of this Unknown with givenColor eyes int withColor(String givenColor) { // ... return 0; } } class Person extends Ancestor { String name; String eyeColor; Ancestor father; Ancestor mother; Person( String name, String eyeColor, Ancestor father, Ancestor mother) { this.name = name; this.eyeColor = eyeColor; this.father = father; this.mother = mother; } //new Person("Jim","brown",new Unknown(),new Unknown()).withColor("brown") == 1 //new Person("Marge","blue",new Unknown(),new Person("Sam","brown",new Unknown(),new Unknown())).withColor("blue") == 1 //To count the family members of this Person, including themselves, with givenColor eyes int withColor(String givenColor) { // ... this.name ... this.eyeColor ... this.father.AncestorMethod() // ... this.mother.AncestorMethod() if ( this.eyeColor.equals(givenColor) ) return 1 + this.father.withColor(givenColor) + this.mother.withColor(givenColor); else return 0 + this.father.withColor(givenColor) + this.mother.withColor(givenColor); } }