CONTENTS | PREV | NEXT | The Java Language Environment |
This chapter has conveyed the essential aspects of Java as an object-oriented language. To sum up:
- Classes define templates from which you instantiate (create) distinct concrete objects.
- Instance variables hold the state of a specific object.
- Objects communicate by sending messages to each other. Objects respond to messages by selecting a method to execute.
- Methods define the behavior of objects instantiated from a class. It is an object's methods that manipulate its instance variables. Unlike regular procedural languages, classes in an object-oriented language may have methods with the same names as other classes. A given object responds to a message in ways determined by the nature of that object, providing polymorphic behavior.
- Subclasses provide the means by which a new class can inherit instance variables and methods from any already defined class. The newly declared class can add new instance variables (extra state), can add new methods (new behavior), or can override the methods of its superclass (different behavior). Subclasses provide code reuse.
Taken together, the concepts of object-oriented programming create a powerful and simple paradigm for software developers to share and re-use code and build on the work of others.