© Kishori Sharan and Adam L. Davis 2022
K. Sharan, A. L. DavisBeginning Java 17 Fundamentalshttps://doi.org/10.1007/978-1-4842-7307-4_9

9. Constructors

Kishori Sharan1   and Adam L. Davis2
(1)
Montgomery, AL, USA
(2)
Oviedo, FL, USA
 
In this chapter, you will learn:
  • What constructors are and how to use them

  • Different types of initializers of a class

  • Declaring final variables, fields, classes, and methods

  • What generic classes are and how to use them

What Is a Constructor?

A constructor is a named block of code that is used to initialize an object of a class immediately after the object is created. The structure of a constructor looks similar to a method. However, the similarity between the two stops right there. They are two different constructs, and they are ...

Get Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 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.