February 2017
Beginner
1056 pages
28h 57m
English
First things first.
—COMMON SAYING
When you create an object of a class using the new operator, you invoke a special kind of method called a constructor. At that time, you often want certain initializing actions to occur, such as giving specific values to the instance variables. A constructor will perform such initializations. In this section, we tell you how to define and use constructors.
A constructor is a special method that is called when you use the new operator to create a new object. Until now, Java has supplied a constructor for us. For example, given the class Species in Listing 5.19 of the previous chapter, we can create a new Species object by writing ...
Read now
Unlock full access