Objects are usable instances of classes. Using the blue
print analogy, a class is a blueprint and object is building made from that
blue print. Classes describe the type of objects.
For example we have a class (say Bike)
class Bike {
}
Then we create object of this class as
Bike myObject = new Bike();
Objects share two characteristic. They have state and
behavior. An object stores its state in fields (variables) and exposes its
behavior through methods.
Software objects are conceptually similar to real world
objects. For example we have real world object Dog.
Dog has state name, color, breed, hungry and behavior barking, fetching, wagging tail
etc.
We represent it in software world as
class Dog
{
string name;
string color;
string breed;
string hungry;
void Barking()
{
//
function definition
}
void Fetching()
{
//
function definition
}
void Waggingtail()
{
//
function definition
}
}
Dog objDog = new Dog();
No comments:
Post a Comment