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 the difference between structure and class in c#?

895


How do destructors and garbage collection work in c#?

879


How will you allow a class to be inherited, but prevent the method from being over-ridden?

930


Is it good to use var in c#?

811


Are value types sealed?

925


Why do we need static class in c#?

944


Explain About friend and Protected friend

841


How do I create a new form in c#?

919


What is winforms c#?

908


In a single .NET DLL how many classes it contains?

883


What is stringbuilder c#?

903


What is the difference while using directive vs using statement ?

942


What is dataview c#?

810


Why do we need to override in c#?

910


How can an inner class access the members of outer class?

927