Creating Variables

In this hour, you are looking at a class of objects called Virus whose sole purpose in life is to reproduce in as many places as possible—much like some people I knew in college. A Virus has several different things it needs to do its work, and these are implemented as the behavior of the class. The information that’s needed for the methods are stored as attributes.

The attributes of an object represent variables needed for the object to function. These variables could be simple data types such as integers, characters, and floating-point numbers, or they could be arrays or objects of classes such as String or Calendar. You can use an object’s variables throughout its class, in any of the methods the object contains. By convention, ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition 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.