A constructor is a special type of method that enables an object to initialize itself when it is created. Constructors have the same name as the class itself and they do not specify a return type.
class Sum { int first; int second; } Sum (int x, int y) // Constructor method { first = x ; second = y ; } int result() { return ( first + second ); } }