From the course: Java 8+ Essential Training: Objects and APIs

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Declare multiple constructor methods

Declare multiple constructor methods - Java Tutorial

From the course: Java 8+ Essential Training: Objects and APIs

Start my 1-month free trial

Declare multiple constructor methods

- [Instructor] A constructor method is a special kind of method that's used to create an object in Java. Whenever you instantiate a class in Java, a constructor method is being called somewhere. If you're using a class from an existing library, the constructor might not always be visible to you. For example, there are more advanced design patterns known as factory classes and builders that hide the use of a simple constructor, but it's always being used at some point. The name of a constructor method has to match the name of the class it constructs. In this code, I'm using a class called MathHelper and I instantiate it with this constructor method. The name of the method matches the name of the class and that's a requirement. Now, this method isn't explicitly defined in the MathHelper class. And in fact from the main class, if I hold down the Control or Command key and then click on the method call, I don't find the method, instead I jump to the class. But the method is there, it's…

Contents