Object
InheritanceObject
class
class
is a subclass of Object
Object
Inheritance Good?Object
has the following methods (among others):
boolean equals(Object obj)
String toString()
Therefore, every class in Java has these methods
Animal
Animal a = new Elephant("Alice");
Animal b = new Elephant("Alice");
What is the behavior of…
a.equals(b)
?a.toString()
?Let’s see!
a.equals(b)
is equivalent to a == b
a.toString()
prints address (not meaningful)How should we…
Animal
s?Animal
as a String
?