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 monitor in C#?
What is a virtual property. Give an example?
What is getenumerator?
can multiple catch blocks be executed for a single try statement?
Is c# pass by value?
What is eager and lazy loading in c#?
Can we declare private class in c#?
What is type cast in C#?
How does the clr work?
What is an interface class in c#?
How many types of serialization are there in c#?
Are string objects mutable or immutable?
How do I use the 'using' keyword with multiple objects?
What is list array in c#?
What is the difference between field and property in c#?