© Kishori Sharan 2017

Kishori Sharan, Beginning Java 9 Fundamentals, https://doi.org/10.1007/978-1-4842-2902-6_9

9. Constructors

Kishori Sharan

(1)Montgomery, Alabama, 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, 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, in their looks. They are two different constructs and they are used for different purposes.

Declaring a Constructor ...

Get Beginning Java 9 Fundamentals: Arrays, Objects, Modules, JShell, and Regular Expressions 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.