O'Reilly logo

Special Edition Using Java 2 Standard Edition by Geoff Friesen, Chuck Cavaness, Brian Keeton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Methods—Defining Behavior

Although variables define the state of a class instance, methods define the associated be havior that controls that state and do the actual work that takes place in your programs. Methods support access specifiers and modifiers in a similar manner to fields. The details of method declarations and syntax were discussed previously in Chapter 4. This section extends that discussion to look at some special uses of methods.

Constructors

A constructor is a special method that is called when a class instance is created. A constructor provides a place for you to define any initialization code you want executed for a new class instance. A constructor is named the same as the class and its declaration looks like a typical method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required