What Is an Object?
Objects are key to understanding object-oriented technology.
Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics:
They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.
Example:
A dog has states-color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
Syntax
class name objectname=new classname();
Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics:
They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.
Example:
A dog has states-color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
Syntax
class name objectname=new classname();
0 comments:
Post a Comment