Object and Classes

6.1 Object and Classes

Until now, we have not really been doing much with objects. The programs so far could just as easily have been written in the language C or Pascal. The following will discuss objects and classes, and how an object-oriented language like Java is different from a procedural language like C.

Objects

Many programs are written to model problems of the real world. It is convenient to have "software objects" that are similar to "real world objects." This makes the program and its computation easier to think about. A software object can store data and perform operations. The data stored in an object are commonly called fields and the operations that an object can perform are called methods.

Class

To create a object in memory, you should have a class. A programmer may define a class using Java, or may use predefined classes that come in class libraries such as the JDK. A class contains fields and methods that define the behavior of the object. You can think of a class as a "blueprint" that can be used to create a particular type of object.
In object-oriented programming, programmers use a programming language (such as Java) to describe the program as various objects. When the program is run, the object are created, and they start "doing things" by running their methods.
In next section we will learn how to define classe and create objects.

No comments:

Post a Comment

Pages