What Objects Are
Objects are created by using a class of objects as a template. The following statements create a class:
public class Modem {}
An object created from this class can’t do anything because it doesn’t have any attributes or behavior. You need to add those to make the class useful, as in the following statements:
public class Modem { int speed; public void displaySpeed() { System.out.println("Speed: " + speed); }}
The Modem
class now should be starting to look like programs you’ve written during Hours 1 through 9. The Modem
class begins with a class
statement, except that it has public
in it. This means that the class is available for use by the public—in other words, by any program that wants to use Modem
objects. ...
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.