Chapter 4: Introducing Classes, Objects, and Methods

1. What is the difference between a class and an object?

A class is a logical abstraction that describes the form and behavior of an object. An object is a physical instance of the class.

2. How is a class defined?

A class is defined by using the keyword class. Inside the class statement, you specify the code and data that comprise the class.

3. What does each object have its own copy of?

Each object of a class has its own copy of the class’ instance variables.

4. Using two separate statements, show how to declare an object called counter of a class called MyCounter.

Image

5. Show how a method called ...

Get Java, A Beginner's Guide, 5th Edition, 5th 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.