constructor example in java

Below code shows how to implement constructor in java Constructor are the special kind of method used to initialize the newly created object Method name and class names are same

class ConstructorClass
{
int x,y;
public ConstructorClass()
{
x=9;
y=32;
}
}
public class ConstructorExample
{
public static void main(String[] args)
{
ConstructorClass Obj = new ConstructorClass();
System.out.println(“Value of x = “+Obj.x+” and y = “+Obj.y);
}

}

Output

Value of x = 9 and y = 32