1: Objects
- Page ID
- 15276
As we learned in the previous chapter, an object is a collection of data that provides a set of methods. For example, a String
is a collection of characters that provides methods like charAt
and substring
.
Java is an “object-oriented” language, which means that it uses objects to represent data and provide methods related to them. This way of organizing programs is a powerful design concept, and we will introduce it a little at a time throughout the remainder of the book.
In this chapter, we introduce two new types of objects: Point
and Rectangle
. We show how to write methods that take objects as parameters and produce objects as return values. We also take a look at the source code for the Java library.