Constructors in Java

Constructors in Java

Constructors are like normal methods or one can say, constructors are special type of methods with following properties

  • Constructors shares the same name as the class name
  • Constructors don’t have return type – not even void
  • Constructors are invoked autometically on creation of object. Mostly used to initialize the object
  • A class can be declared without a constructor. In this particular situation, a no-arg constructor with an empty body is implicitly declared in the class, know as default constructor
  • Constructors have none, one or many parameters
  • Constructors can be overloaded. Multiple constructors with same name but different type / number of parameter

Constructor, Example

Constructors

Constructors

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.