Answer Posted / vinay tiwari
//Constructor is a special member function its name is same
//as class name.It is used to allocate memory to object and
initilizes
//its field .you can also say that it is used to initilized
the object
//constructor invoke automatically when the object of its
class is created
class a
{
public int i;
public a()//default constructor
{
i=10;
}
public a(int x)//parameterized constructor
{
i=x;
}
public a(a ob)//copy constructor
{
i=ob.i;
}
public void display()
{
System.Console.WriteLine(i);
}
}
class b
{
static void Main(string [] args)
{
a ob=new a();
ob.display();
a ob1=new a(77);
ob1.display();
a ob2=new a(ob);
ob2.display();
}
}
| Is This Answer Correct ? | 10 Yes | 2 No |
Post New Answer View All Answers
What is the purpose of dictionary in c#?
Describe the difference between inline and code behind - which is best?
Tell me the difference between call by value and call by reference.
What does string format do?
Explain the difference between const and static read-only?
What is iqueryable in linq?
Why we use methods in c#?
What are boxing and unboxing?
the c# keyword .int. Maps to which .net type?
What does out mean c#?
What are destructors in C#?
Why do we use interfaces in c#?
What are the advantages of using partial classes?
Can struct be static in c#?
What are the 2 types of data types available in c#?