Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Explain constructor.

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


Please Help Members By Posting Answers For Below Questions

What is monitor in C#?

1007


What is a virtual property. Give an example?

931


What is getenumerator?

844


can multiple catch blocks be executed for a single try statement?

974


Is c# pass by value?

889


What is eager and lazy loading in c#?

987


Can we declare private class in c#?

908


What is type cast in C#?

986


How does the clr work?

903


What is an interface class in c#?

1091


How many types of serialization are there in c#?

889


Are string objects mutable or immutable?

924


How do I use the 'using' keyword with multiple objects?

945


What is list array in c#?

867


What is the difference between field and property in c#?

927