Concept

How does Java handle default and multiple constructors?

ComputerScienceOne / Constructors

"Java allows us to define multiple constructors, or even no constructor at all. If we do not specify a constructor, Java provides a default, no argument constructor. This constructor uses default values for all member variables (zero for numerical types, false for boolean types, and null for objects). If we do specify a constructor, this default constructor becomes unavailable. However, we can always “restore” it by explicitly defining it.\n\n1 public Student() {\n\n2 this.firstName = null;\n\n3 this.lastName = null;\n\n4 this.id = 0;\n\n5 this.gpa = 0.0;\n\n6 }\n\nAlternatively, we can define constructors that accept a subset of variable values.\n\n1 public Student(String firstName, String lastName) {\n\n2 this.firstName = firstName;\n\n3 this.lastName = lastName;\n\n4 this.id = 0;\n\n5 this.gpa = 0.0;\n\n6 }"

Related Ideas

How does Java handle default and multiple constructors? | ComputerScienceOne | Bifalgorithm | Bifalgorithm