Disney web site - Chapter 8 Object-Based Programming 437 public class Elevator
Friday, August 17th, 2007Chapter 8 Object-Based Programming 437 public class Elevator { // class attributes private boolean moving; private boolean summoned; private int currentFloor = 1; private int destinationFloor = 2; private int capacity = 1; private int travelTime = 5; // class objects private ElevatorDoor elevatorDoor; private ElevatorButton elevatorButton; private Bell bell; // class constructor public Elevator() {} // class methods public void ride() {} public void requestElevator() {} public void enterElevator() {} public void exitElevator() {} public void departElevator() {} } This concludes the basics of forward engineering. We return to this example at the ends of Thinking About Objects Section 9.23 and Section 10.22 to incorporate inheritance, interfaces and event handling. SUMMARY OOP encapsulates data (attributes) and methods (behaviors) into objects; the data and methods of an object are intimately tied together. Objects have the property of information hiding. Objects might know how to communicate with one another across well-defined interfaces, but they normally are not allowed to know how other objects are implemented. Java programmers concentrate on creating their own user-defined types called classes. The non-static data components of a class are called instance variables. The static data components of a class are called class variables. Java uses inheritance to create new classes from existing class definitions. Every class in Java is a subclass of Object. Thus, every new class definition has the attributes (data) and behaviors (methods) of class Object. Keywords publicand private are member access modifiers. Instance variables and methods declared with member access modifier public are accessible wherever the program has a reference to an object of the class in which they are defined. Instance variables and methods declared with member access modifier private are accessible only to methods of the class in which they are defined. Instance variables are normally declared private and methods are normally declared public. The public methods (or public services) of a class are used by clients of the class to manipulate the data stored in objects of the class. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01