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
Is there any sample c# code for simple threading?
Can you specify an access modifier for an enumeration?
what is an exception in .net?
How do you determine whether a string represents a numeric value?
What is the main purpose of xml?
What is the use of 0 in c#?
What is meant by enumerable in c#?
What is hierarchical inheritance in c#?
What are get and set in c#?
Can we use "this" command within a static method?
Why generics are used?
What does return do in for loop?
Explain why do I get an error (cs1006) when trying to declare a method without specifying a return type?
What does this keyword mean in c#?
What is variable in c#?