Constructor in Java.

A constructor in Java is similar to a method that is invoked when an object of the class is created. It has the same name as its class and is syntactically similar to a method.

Code :