Class Declaration
A class is defined by a class declaration, which follows this basic form:
[public] class ClassName {class-body}
The public keyword indicates that this class is available for use by other classes. Although it’s optional, you usually include it in your class declarations so that other classes can create objects from the class you’re defining.
The ClassName
provides the name for the class. You can use any identifier you want to name a class, but the following three guidelines can simplify your life:
Begin the class name with a capital letter. If the class name consists of more than one word, capitalize each word: for example, Ball, RetailCustomer, and GuessingGame.
Whenever possible, use nouns for your class names. Classes create objects, and nouns are the words you use to identify objects. Thus, most class names should be nouns.
Avoid using the name of a Java API class. No rule says that you absolutely have to, but if you create ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access