Class and object initialization in Java

Class and object initialization in Java

Classes and objects in Java must be initialized before they are used. You’ve previously learned that class fields are initialized to default values when classes are loaded, and that objects are initialized via constructors—but there is still more to initialization. This tutorial introduces all of Java’s features for initializing classes and objects.

What you’ll learn in this Java tutorial

How to initialize a Java class
How to work with class initialization blocks
How to initialize Java objects

download
Download the source code for example applications in this tutorial. Created by Jeff Friesen for JavaWorld.

How to initialize a Java class

Before we explore Java’s support for class initialization, let’s recap the steps of initializing a Java class. Consider Listing 1.

To read this article in full, please click here