Type of Java constructors

Java Programming Java8Object Oriented Programming

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.
   }
}
raja
Updated on 05-Mar-2020 12:26:33

Advertisements