Previous Topic Next topic Print topic


Constants - in COBOL and Java

COBOL Java
class-id Students.

*> optionally public etc., and may reference constants in other classes
01 MAX_STUDENTS binary-long constant value 25 + 3.

*> Can set to a const or var; may be initialized in a constructor
01 MIN_DIAMETER float-short value 4.93 initialize only.

method-id Main().
    display MAX_STUDENTS
    display MIN_DIAMETER
end method.

end class.
public class constants
{
    // constant value cannot be changed ;
    public static final int MAX_STUDENTS = 25 + 3;

    // This value can be assigned at declaration
    // OR
    // assigned in constructor
    // (not both)
    public final float MIN_DIAMETER = 4.93f;

}

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.

Previous Topic Next topic Print topic