December 1999
Intermediate to advanced
816 pages
20h 27m
English
There are two kinds of initialization you can do for an object: default and explicit.
Here's an example of default initialization:
public class LibraryCard
{
String patronID;
float outstandingFine;
int booksCheckedOut = 0;
}
This class has three data members. The first two, patronID and outstandingFine, have no values assigned to them. The third, booksCheckedOut, is set to zero. When an instance of the LibraryCard class is created, the value of booksCheckedOut starts off as zero. The other two data members are assigned values by the system. The value a data member gets depends on the data type of data member. That is, all data members are initialized to default values if they are not explicitly initialized. Here's ...
Read now
Unlock full access