Encapsulation means that a group of related properties,
methods, and other members treated as a single unit or object. This hides the
data from being accessed from outside a class directly, only through the
functions inside the class is able to access the information.
Programming Tutorials on XHTML, CSS, JavaScript, JQuery, JSON, Python, Django, Amazon Web Services, ASP.NET, Web Forms, and SQL
Thursday, November 28, 2013
What is difference between class and object?
Class is a blue print or some template and object is a building
created from this blue print or template. Class is a more abstract definition
of something and object is the real thing that belongs to that class.
For example
Class:
class Bike {
}
Object:
Bike myObject = new Bike();
What is an Object in Object Oriented Programming?
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();
Saturday, November 9, 2013
What is Class?
A class is the blue print from where individual objects are
created. For example in real world, we
may find many individual objects of same kind. There may be thousands of bikes
in existence, all of the same make and model. Each bike was built from the same
set of blueprints and therefore contains the same component. In object oriented
terms, we say that our bike is an instance of the class of objects known as
bikes.
The following Bike class is one of implementation of a bike.
class Bike {
int Speed = 0;
int Gear = 0;
void SpeedUp(int increment)
{
Speed += increment;
}
void ApplyBreakes(int decrement)
{
Speed -= decrement;
}
}
Simple example of class is
class SampleClass {
}
What is Object Oriented Programming?
Object oriented programming is a programming language model
organized around objects rather than action, and data rather than logic. Objects
have both data fields and associated procedures called methods. Objects are
instances of classes and used to interact with one another to design applications
and computer programs.
Subscribe to:
Posts (Atom)