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
Will the following code compile and run?
Can we extend static class in c#?
How can you set image source dynamically from c# application to ”test.png” file?
Why do we use delegates?
Why do I get a "cs5001: does not have an entry point defined" error when compiling?
What do you understand by 'access specifiers' in C#?
Is c# a backend language?
Why are strings immutable c#?
Can scriptable objects have methods?
What does void mean unity?
What is string concatenation?
Is arraylist generic in c#?
In languages without exception-handling facilities, we could send an error-handling procedure as a parameter to each procedure that can detect errors that must be handled. What disadvantages are there to this method?
Why to use “finally” block in c#?
What is meant by console programming?