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 a dynamic assembly?
What happens if a static constructor throws an exception?
how can one use hcl and c sharp together?
How do I trim a space in c#?
What is difference between static and readonly in c#?
What is sorting in c#?
What is unrecognized escape sequence in c#?
What are extensions in c#?
What is an escape sequence?
Is static class thread safe in c#?
What are the basic string operations? Explain.
Can the nested class access, the containing class. Give an example?
Can you explain template pattern?
What is hashmap in c#?
What is form feed in c#?