Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

Workshop 167

Q&A


Q. Most Java programs we’ve created up to this point have not used
extendsto inherit from a superclass. Does this mean they exist out-
side of the class hierarchy?
A. All classes you create in Java are part of the hierarchy because the
default superclass for the programs you write is Objectwhen you aren’t
using the extendskeyword. The equals()andtoString()methods of
all classes are part of the behavior that automatically is inherited from
Object.

Q. Why do people yell “eureka!” when they’ve discovered something?
A. Eureka is borrowed from ancient Greek,where it meant “I have found
it!” The phrase was supposedly exclaimed by the Greek scholar
Archimedes when he stepped into a bath.
What did the Greek discover in the bath? The rising water level,which
led him to understand that the volume of displaced water must equal
the volume of his body parts.
The story about Archimedes was spread two centuries later by Vitruvius
in his multivolume De Architectura, a book about architecture.
“Eureka” has been in the California state seal since 1849,referring to
the discovery of gold near Sutter’s Mill a year earlier.

Workshop


To determine what kind of knowledge you inherited from the past hour ’s
work, answer the following questions.


Quiz



  1. If a superclass handles a method in a way you don’t want to use in the
    subclass,what can you do?
    A. Delete the method in the superclass.
    B. Override the method in the subclass.
    C. Write a nasty letter to the editor of the San Jose Mercury News
    hoping that Java’s developers read it.

Free download pdf