Classes in Object oriented programming
Class Example- A class is simply a representation of a type of object.
- Class is composed of three things: a name, attributes, and operations.
- There was some major problems in earlier approach is that the data and the functions working upon the data being separated.
- But the rule of Object oriented says that if the data and functions acting upon the data can go together let them be together, So we define a unit which contains data and its function together as a Class.
The Employee class would be like this
/*------------------------------------------------------------*/
public class Employee // class name
{
int
EmployeeID; //
These are instance variables. They belong to object.
string
EmployeeName; // These are attributes of a class at any point of time the value of these variables determines the state of the object.
string
EmployeeAddress;
double
EmployeeBasicSalary;
public void AddDetails()
// Methods or Member function. These determine the behavior of a class
{
// Logic to
add the details of employee.
}
public void PrintDetails()
{
// Logic to
print the details of employee.
}
}
/*------------------------------------------------------------*/
Objects in Object oriented programming
- An object is a software bundle of variables and related methods.
- Objects are related to real life such as people,cars and houses.
- Objects are instances of classes
- The object is declared in the below way
- An object has following characteristics
- Attribute: The set of values of an attribute of a particular object is called its state. In Class Program attribute can be a string or it can be a integer or any other simple or complex Datatype.
- Behaviour: Every object has behavior. If a behavior of an object needs to be performed, then the corresponding method is called.
- Identity: Each time an object is created the object identity is been defined.This identity is usually created using an identifier which is derived from the type of item
No comments:
Post a Comment