Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

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.

Example

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();
   }
}

Output

This is an example of a constructor
Updated on: 2019-07-30T22:30:20+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements