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
how to implement a web service in .net
How more than one version of an assembly can keep in same place?
Explain About Global.asax
What is object array in c#?
How do you declare an interface in c#?
Is c# an open source?
How to implement a singleton design pattern in c#?
What is an abstract class c#?
Explain static class members.
What is the difference between dynamic and var in c#?
What is the symbol used for in c#?
How can you sort strings in array that are passed to method as arguments?
What is a event in c#?
What is an inheritance in c#?
What is serialization and deserialization in c# with example?