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 many constructors can a class have c#?
What's c# ?
What is the usage of Enumeration in C# Programming and is it good to use or not ?
Can a static class contain non static members?
How many digits are in an integer?
When should I throw an exception?
What is difference between ienumerable and list?
Can we make a class private in c#?
What is a decimal in c#?
What is equal c#?
How many bytes is an int in c#?
What are primitive data types in c#?
What is difference between the "throw" and "throw ex" in .net?
Write the syntax for catching an exception in c#?
What are delegate methods?