Type of Java constructors



There are two types of constructor java supports −

  • Default constructor: A constructor with no arguments
  • Parameterized constructor: A constructor with parameters.

Example

public class Puppy {
   //Default constructor
   public Puppy() {
   }
   //Parameterized constructor
   public Puppy(String name) {
      // This constructor has one parameter, name.
   }
}

Advertisements