Classes, Objects, Methods
}Analogy to help you understand classesand their contents.
§Suppose you want to drive a car and make it go faster by pressing down on its accelerator pedal.
§Before you can drive a car, some one has to design it.
§A car typically begins as engineering drawings, similar to the blueprints used to design a house.
§These include the design for an accelerator pedal to make the car go faster.
}Performing a task in a program requires amethod.
§The method describes the mechanismsthat actually perform its tasks.
§Hides from its user the complex tasks that it performs, just as the accelerator pedal of a car hides from the driver the complex mechanisms of making the car go faster.
}In Java, a class houses a method, just asa car’s engineering drawings house the design of an accelerator pedal.
}In a class, you provide one or more methods that are designed to perform the class’s tasks.
}You must build an object of a class before a program can perform the tasks the class describes how to do.
§That is one reason Java is known as an object-oriented programming language.
}When you drive a car, pressing its gas pedal sends a message to the car to perform a task—make the car go faster.
}You send messages to an object—each message is implemented as a method call that tells a method of the object to perform its task.



