Constructor
A constructor initialize an object immediately after object creation.it is called constructor.it doesnt have return type.it should have the same name as the class.It is similar tomethod with or without argument.it is called immediately after object creation.
Example
class first
{
int x;
int y;
first()
{
x=10;y=10;
}
int calc()
{
return x*y;
}
}
class mainPrg
{
public static void main(String args[])
{
first f=new first();
f.calc();
}
}
why we need construtor?
Click theLink
No comments:
Post a Comment