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
Define an abstract class?
What is the difference between mobile application and desktop application?
What language is arduino?
what is IComparable
Can you mark static constructor with access modifiers?
write a C# Program add two matrix ?
Explain the difference between .net and c#?
Define a strong name in .net?
Is c# easier than javascript?
What is the difference between struct and class in c#?
Is c# 8 released?
What is use of singleton class in c#?
What are the drawbacks of extending an interface as opposed to extending a class?
What are the different states of a thread?
Can you use foreach iteration on arrays in c#?