Defining a Class’s Methods
In this lesson, we will define methods within a class definition.
We'll cover the following
We define a method in much the same way that we define a constructor. Like constructors, methods have headers, but their syntax is slightly different, as we will see.
The method greet
The public methods of a class define the behaviors that objects of the class have. Our class Greeter
has the method greet
, which displays an object’s greeting. Its definition within the class appears as follows in lines 5 through 9:
Get hands-on with 1400+ tech skills courses.