
a programming methodology in which the programmer can define not only data types, but also methods that are automatically associated with them.Ageneral type of an object is called a class. Once a class has been defined, specific instances of that class can be created.
The same name can be given to different procedures that do corresponding things to different types; this is called polymorphism. For example, there could be a "draw" procedure for circles and another for rectangles.
Some uses for object-oriented programming include the following:
Here is an example of object-oriented programming in Java. Imagine a program that manipulates points, lines, and circles. A point consists of a location plus a procedure to display it (just draw a dot). So the programmer defines a class called pointtype as follows:
The class pointtype is defined to include two integer variables (x and y) and one method (draw). (The class also would include a
Now variables of type pointtype can be declared, for example:
Here the objects a and b each contain an x and a y field; x and y are called instance variables. In addition, a and b are associated with the draw procedure. Here's an example of how to use them:
This sets the x and y fields of a to 100 and 150, respectively, and then calls the draw procedure that is associated with a (namely pointtype.draw). (The g stands for graphics.)
Now let's handle circles. A circle is like a point except that in addition to x and y, it has a diameter. Also, its draw method is different. We can define circletype as another type that includes a pointtype, and it adds an instance variable called diameter and substitutes a different draw method. Here's how it's done:

Your program would create a new object of class circletype (call it c), define values for the variables, and then call the method circletype.draw to display the circle on the screen. See the book's web page, www.termbook.com, for an example.
It is important to remember that instance variables belong to individual objects such as a, b, and c, but methods (procedures) belong to object types (classes). One advantage of object-oriented programming is that it automatically associates the right procedures with each object: c.draw uses the circle draw procedure because object c is a circle, but a.draw uses the point draw procedure because object a is a point.
The act of calling one of an object's methods is sometimes described as "sending a message" to the object (e.g., c.draw "sends a message" to c saying "drawyourself").All object-oriented programming systems allow one class to inherit from another, so the properties of one class can automatically be used by another class. For example, there is a standard Java class called Applet which contains the code needed to display an applet on the web. When you write your own applet, it will inherit from (extend) this class, so you don't need to recreate that code yourself.