How do I write constructor names in Java?

Declaring a constructor is in Java is similar to methods. While naming the constructor of a class in Java you need to keep the following points in mind.

  • The name of the constructor should be the same (same case) as the class name (along with the access specifier).
  • A constructor should not have any return type.
  • Constructor cannot be static, final, abstract and, synchronized.


Following Java program is an example of a constructor.

Live Demo

public class Sample {
   Sample() {
      System.out.println("This is an example of a constructor");	   
   public static void main(String args[]) {
      new Sample();


This is an example of a constructor