Section 3.4 Account Class: Initializing Objects with Constructors

• Each class you declare can optionally provide a constructor with parameters that can be used to initialize an object of a class when the object is created.

• Java requires a constructor call for every object that’s created.

• Constructors can specify parameters but not return types.

• If a class does not define constructors, the compiler provides a default constructor (p. 83) with no parameters, and the class’s instance variables are initialized to their default values.

• If you declare a constructor for a class, the compiler will not create a default constructor for that class.

• The UML models constructors in the third compartment of a class diagram. To distinguish a constructor ...

Get Java™ How To Program (Early Objects), Tenth 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.