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
Published on 22-Apr-2018 20:20:59
Advertisements