When creating a class that maintains any state (that is almost any class that has class members), it can be very useful to create a constructor that can perform any required initialization.
Creating constructors is not tricky; however, NetBeans provides a handy shortcut to save time and increase developer productivity.
First we will need to create a new project, so please refer to the recipes in Chapter 1, Using NetBeans Projects, for creating Java projects. To help follow this recipe, when creating a project, enter CreatingConstructors
as the project name.
When the Projects explorer shows the CreatingConstructors
project, expand the CreatingConstructors
node if it is not already expanded.
We will now create an empty class and show how constructors can be added to it with the following steps:
Right-click on the
CreatingConstructors
project, and select New and Java Class….On the New Java Class dialog, type
Shape
under the Class Name field.On the...