How can you squeeze four students inside a computer? The answer is, by using a series of zeros and ones. That wasn t the punch line you expected to hear, but it is true. Computers view students ”and the world ”as a bunch of zeros and ones, collectively called data . And clever programmers manipulate data to represent real-world objects by using a class . No, not a class of students, but a class that represents a real object inside a program. You ll be learning about classes in this chapter.
A real-world object, such as the registration form used to register for a course, consists of attributes and behaviors (see Figure 2-1). An attribute is data associated with an object. The course name, course number, and your name and student number are examples of data associated with the registration form. A behavior is something performed by an object, such as processing, modifying, or canceling a course registration.
A programmer s job is to use an object-oriented programming language to translate attributes and behaviors of a real-world object into a class that consists of attributes and methods understood by a computer.
Note | Method and function are terms used to define a behavior in a program. Java programmers use the term method , and C++ programmers call it a function . Regardless of the name, a method and a function are used for the same purpose. Let s keep things simple when talking about behavior by using the term method throughout this book when referring to behavior, unless we are talking specifically about a C++ program. |