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 - Java Tutorial
From the course: Java 8+ Essential Training: Objects and APIs
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
About encapsulation3m 46s
-
Use the Java runtime classes4m 45s
-
(Locked)
Wrap code in static methods5m 56s
-
(Locked)
Declare and use custom classes4m 9s
-
(Locked)
Organize code with packages3m 46s
-
(Locked)
Create and use instance methods2m 27s
-
(Locked)
Manage state with instance variables7m 31s
-
(Locked)
Declare multiple constructor methods5m 2s
-
(Locked)
Use static fields as constants5m 51s
-
(Locked)
Declare and use enum types3m 44s
-
(Locked)
Organize code with nested types4m 15s
-
(Locked)
-
-
-
-
-