Basics On Objects and Class

*Yes Object Oriented Programming that is related to our real world Objects.So we need to First understood with this object.What is real world object ?

Ans.: First think about our real-world object such as a car.If we analyze car objects state we can found that car has some state that's are: Car's current speed,current fuel level,current direction,current engine temperature etc. If you analyze its behavior we can found: changing gear,changing speed,changing direction.
Yes every car has its own identity such has car's License Number.  So if we consider car object we can find it has three property-state,behaviors and identity.So if we analyze other real world objects we can found these three things.So we can claim that objects consists of three things state,behaviors and identity.

*Now come to our Object in programming.What is object?

Ans.: In object oriented programming Object is other  form of real world object.We can use a objects state and identity in variables such  as cars speed,fuel-level,engines temperature etc. And its behavior controls by objects functions(methods).behavior always control by its method.So we can say that objects forms with some variables which related to state and identity and methods which relate to behavior of real world object.

 *What is Class in OOP?

Ans.:We Consider so many cars that are belongs to same manufacturer.every car has its own identity that differ it from others.But we represent all cars state and behavior to a Car Class. And then we create as many car  objects  from it.


like class Car:

calss Car{
double speed = 0.00;
int gear =1;
String licenseNumber = "123";
double fuelLevel = 10.00;
string direction = "North";

void increaseSpeed(double increment)
{
       speed+=increment;
}
void decreaseSpeed(double decrement)
{
      speed-=decrement;
}
void changeGear(int changeValue)
{
     gear = changeValue;
}
void changeDirection(String direction)
{
      direction = direction;
}
}

so we can say that A class is a static piece of code that consists of attributes which don’t change during the execution of a program.

but different car objects has its own property.Class is the blueprint of individual objects.
Reactions

Post a Comment

0 Comments