Defining Classes

Because you have created classes during each of the previous days, you should be familiar with the basics of class definition at this point. A class is defined via the class keyword and the name of the class, as in the following example:

class Ticker { 
    // body of the class
}

By default, classes inherit from the Object class. It's the superclass of all classes in the Java class hierarchy.

The extends keyword is used to indicate the superclass of a class. Look at the following subclass of Ticker:

class SportsTicker extends Ticker { 
    // body of the class
}

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.