Java Static Modifier

Objectives         Introduction         Commentary         Interactive Exercises


This lesson will take a closer look at defining and using static and non-static variables and methods.

Recall the following fundamental information that supports understanding Java Static Modifier:

1. An object is an instance of a class.


2. To create an instance of a typical class you can do the following:

Classname myinstance = new Classname();

For example:

String myStringinstance = new String("Hello, World");

3. In many cases, you can "instantiate" many instances of a class.

For example:

String myStringinstance1 = new String("Welcome");

String myStringinstance2 = new String("To the Java course");

String myStringinstance3 = new String("Your instructor is Dr. Franklin Smith");

4. Within each class definition, variables and methods can be defined. Each of these can have

one or more modifiers associated with them. Examples of modifiers include private, public, static

and many others.

As you read more about this topic in this lesson and other literature, keep in mind the following:

  • static variables (and methods) are often referred to as class variables (and methods) non-static variables (and methods) are often referred to as instance variables (and methods)

  • by default, a variable or method is non-static.


2006 University of Maryland University College home