Answer Posted / k.gnaneshwar
*-> Constructor is used for initializing the variables
during object creation.
*-> that means the code required for initializing the
variable should be writen in constructor.
CONSTRUCTOR DECLARATION RULES
* Constructor look like a method.
* Constructor have no return type.
* Constructor name should be same name as the class name.
(prog)
class simpleAddition
{
int a,b; //variable declaration
simpleAddition() //constructor declaration
{
a=6;
b=3;
}
int add() // method declaration
{
return a+b;
}
}
output:- 9
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
What is the difference between structure and class in c#?
How do destructors and garbage collection work in c#?
How will you allow a class to be inherited, but prevent the method from being over-ridden?
Is it good to use var in c#?
Are value types sealed?
Why do we need static class in c#?
Explain About friend and Protected friend
How do I create a new form in c#?
What is winforms c#?
In a single .NET DLL how many classes it contains?
What is stringbuilder c#?
What is the difference while using directive vs using statement ?
What is dataview c#?
Why do we need to override in c#?
How can an inner class access the members of outer class?