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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access