6.3. Chaining Constructors Using this() and super()
Constructors are discussed in Section 4.4 on page 117. Other uses of the keywords this and super can be found in Section 6.2 on page 233.
this() Constructor Call
Constructors cannot be inherited or overridden. They can be overloaded, but only in the same class. Since a constructor always has the same name as the class, each parameter list must be different when defining more than one constructor for a class. In Example 6.6, the class Light has three overloaded constructors. In the non-default constructor at (3), the this reference is used to access the fields shadowed by the parameters. In the main() method at (4), the appropriate constructor is invoked depending on the arguments in the constructor ...
Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.