Initialization of Data Members

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 ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.