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 class is underneath the sortedlist class?
What is the purpose of a namespace?
Overloaded constructor will call default constructor internally?
What's different between c# and c/c++?
What is string literal in c#?
Why we use get and set property in c#?
Why do we use delegates in c#?
Why do we need constructor in c#?
Explain publishers and subscribers in events.
what is a enumeration in c#
What is a c# delegate?
What is short in c#?
Which of the following API is used to hide a window?
What is the default value of boolean variable?
What is uint c#?