- This Constructor is created by the programmer
- This Constructor doesn’t accept any arguments or parameters
- In General this constructor is used to initialize required values into the data fields But there is no restriction to write particular code into the constructor
Example:-
Class Diagram :-
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
CAConstructors
{
class ClsEmployee1
{
int
EmpId, EAge;
string
EName, EAddress;
public
ClsEmployee1()
{
this.EmpId
= 9;
this.EName
= "Sampath kumar";
this.EAddress
= "Karimnagar";
this.EAge
= 25;
}
public
void DisplayEmpData()
{
Console.WriteLine("Employee Id is :-" + EmpId);
Console.WriteLine("Employee Name is :-" + EName);
Console.WriteLine("Employee Address is :-" + EAddress);
Console.WriteLine("Employee Age is :-" + EAge);
}
}
class ClsUDConstructor
{
static
void Main(string[]
args)
{
ClsEmployee1
Obj1 = new ClsEmployee1();
ClsEmployee1
Obj2 = new ClsEmployee1();
Obj1.DisplayEmpData();
Obj2.DisplayEmpData();
Console.Read();
}
}
}
|
No comments:
Post a Comment