Introduction• An object is a software bundle of variables and related methods. • Objects are related to real life scenario • Class is the general thing and object is the specialization of general thing • Objects are instance of classes. • Declaration of an Object in C#.NET • ClassName objectName=new ClassName(); E.g.: Person objPerson= new Person(); An object is characterized by concepts like: • Attribute • Behavior • Identity 1. What is an Attribute? • Attributes define the characteristics of a class.
• 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
Example of Attribute: 2. What is a Behavior? • Every object has behavior
• In C#, behaviors of objects are written in methods.
• If a behavior of an object needs to be performed, then the corresponding method is called.
Example of behavior: 3. What is an 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
Example of Identity:
Sample Code Lines
using System;
class SalaryCheque
{
public string _EmployeeName;
public int _Amount;
public string EmployeeName(string name)
{
_EmployeeName = name;
return _EmployeeName;
}
public void EmployeeType(int type)
{
if (type == 1)
{
this._Amount = 50000;
}
if (type == 2)
{
this._Amount = 27000;
}
if (type == 3)
{
this._Amount = 5000;
}
}
public void DisplayCheque()
{
Console.WriteLine("This Month Salary for " + _EmployeeName + " is " + _Amount);
}
}
class SalaryChequeDisplay
{
static void Main()
{
string _name;
int _employeeType;
Console.WriteLine("Please Enter Employee Name");
_name = Console.ReadLine();
Console.WriteLine("Enter Employee type 1 for Manager 2 for Assistant Manager 3 for Worker");
_employeeType = Convert.ToInt16(Console.ReadLine());
SalaryCheque objsal = new SalaryCheque();
objsal.EmployeeName(_name);
objsal.EmployeeType(_employeeType);
objsal.DisplayCheque();
}
ConclusionIn this article, i have explained what is object and basic concept of the object. i hope this is help to you all. |