Beginning a Class Definition

In this lesson, we will look at the general outline of the syntax for the Greeter class.

Defining the class Greeter

The definition of the class Greeter has the following form:

public class Greeter
{
   . . .
} // End Greeter

The access modifier public indicates the class’s availability. All clients may use this class. Next is the reserved word class and the name of the class. This initial portion of the definition is the class header. After the header, braces delineate the class’s definition.

A class designer must decide what data, if any, will be represented by objects of the class. For example, each Greeter object has a string associated with it that is its greeting. Thus, in the class definition, we declare a string for this purpose. The class now appears as follows:

public class Greeter        // Class header
{
   private String greeting;
   . . .
} // End Greeter

Get hands-on with 1200+ tech skills courses.