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
Can non-default constructors be used with single call sao?
Is string immutable in c#?
What is a hash table in c#?
Is stringbuilder faster than string concatenation c#?
What is asp net c# corner?
What is c-sharp (c#)?
write a program to find the biggest palindrome in the given string
What is generic in c#?
what is the difference between interface and multiple interface?
What is the syntax for calling an overloaded constructor within a constructor?
Why delegates are type safe in c#?
Why static variables are used?
Is c sharp open source?
Can we have multiple threads in one app domain?
Why abstract class is not instantiated in c#?