that Frog objects can do AND more. They understand all the messages in the protocol of Frog objects AND the messages up() and down(). They also have all the attributes that Frog objects do AND the additional attribute height.
subclass is an extended version of its superclass. In this scenario: superclass: Frog subclass: HoverFrog So, the subclass is derived from its superclass.
of the subclass to have all the same attributes and to understand the same set of messages as the superclass. • But we also want the sub to have additional attributes and/ or to understand more messages than the superclass.
objects have at least the attributes and protocol of Frog objects. • In addition HoverFrogs have the attribute height and understand the additional messages up(), upBy(), down(), and downBy().
that Frog is the superclass of HoverFrog. Note how the Toad class is present but that it is not a subclass or a superclass of either Frog and HoverFrog.
subclass relationship. We say that a HoverFrog ‘is a’ kind of Frog. In other words, HoverFrog objects are an extension of Frog objects. They build upon it. The HoverFrog class is a blueprint that builds upon the blueprint of the Frog class.
a subclass relationship between two classes of objects (by recognising an ‘is a’ relationship) then we only need to define the common attributes and protocol of both classes once – in the superclass. Then we know that the subclass will inherit these as a bare minimum, to which we can further extend the subclass by adding more.
subclass. • How a subclass might differently initialise the common attributes it shares with the superclass. In our case, HoverFrog objects and Frog objects both have position initialised to 1. But they could be different. • How we might override the behaviour of an inherited message. In our case every message that HoverFrog inherits from Frog behaves the same for both (e.g. left() and home()). But what if we wanted different behaviour from the same message?
way to the message left() ? A: Yes. Since HoverFrog is the subclass of Frog, HoverFrog objects can understand all the messages as defined in the Frog class. Since left() is defined in the Frog class then HoverFrog objects understand this.
up() to an instance of Frog? A: An error would occur. The message up() is not in the protocol of Frog, it is in the protocol of HoverFrog. Since Frog is NOT a subclass of HoverFrog (it is the other way around), it does not inherit its protocol, so can’t understand up().