Symbolic Constants (final Variables)

Python Java
All variables can be reset at any time. There are no symbolic constants. Symbols such as True, False, and None are reserved words. Final variables serve as symbolic constants. A final variable declaration is qualified with the reserved word final. The variable is set to a value in the declaration and cannot be reset. Any such attempt is caught at compile time.

Example:

public class Student{

     public static final int NUM_GRADES = 5;

     private String name;
     private int[] grades;

     public Student(String name){

         this.name = name;
         this.grades = new int[NUM_GRADES];
    }
}

© Ken Lambert. All rights reserved.