An identifier's duration (or lifetime) is the period during which that variable exists in memory. Some identifiers exist briefly. Others are repeatedly created and destroyed. Still others exist for the entire execution of the program.
public class Duration extends JApplet { static int count = 0; // static variable (only one copy) int total = 0; // instance variable (copy in each instance) public void start() { MethodA(); MethodA(); } public void MethodA() { int sum = 0; // local variable sum += 5; total += sum; count++; System.out.println("count " + count + " sum " + sum + " total " + total); } }
Maintained by John Loomis, last updated 1 June 2000