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 type of data type conversion happens when the compiler encounters the following code?
What is the difference between an implicit conversion and an explicit conversion?
Can a constructor be static in c#?
What is generic in c#?
How big is a float?
What is private void in c#?
Between windows authentication and sql server authentication, which one is trusted and which one is untrusted?
What is the difference between returning iqueryable vs ienumerable?
What is the default value of string in c#?
How to declares a two-dimensional array in C#?
What kind of the information stored inside the assembly?
What is a hash table c#?
Can I define my own exceptions?
What are some examples of desktop applications?
what is generics? can u explain 5 to 6 examples on generics that covers class,method,structure,list,delegates?