Constructors in Java

It would be simpler and more concise to initialize an object when it is first created, Java supports a special type of method that enable an object to initialize itself when it is created that is called Constructor.
Rule of Constructor :
1. The constructor has the same name as the class itself.
2. Constructor don’t specify a return type, not even void .
3. In Java, a constructor can’t be abstract, final and static.

Example :

class square
{
 int length, width;
square(int x, int y)  // creating constructor
{
 length=x;
 width=y;
}
int area()
{
 return(length*width);
}
}