O'Reilly logo

PURE Java™ 2 by Kenneth Litwak

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

Classes

Classes define what an object will be like, its state and behavior. If I create a primitive and initialize it as in

int x = 6;

there is a memory location set aside that contains the number 6 as an int. x refers directly to that memory location. If, however, I code

JFrame mainFrame = new Frame();

mainFrame is not the name of the JFrame object, but an object reference to the JFrame object. This has important ramifications. Consider this little class definition:

public class Book
     {
      boolean reservedStatus;
       int checkOutPeriod;
       String title;
     }

When another class does

Book b = new Book();

memory is allocated for the data members reservedStatus and checkOutPeriod. Furthermore, that memory is given default, initial values, such as false ...

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