Introduction to OOP Chapter 4: Classes and Methods: next previous audio real text

Constant Data Fields

Some languages allow data fields to be declared as constant (const modifier in C++, final in Java, other languages have other conventions).

Constant data fields can be declared as public, since they cannot be changed.


class PlayingCard { // Java example
	...
    public static final int Spade = 1;
    public static final int Diamond = 2;
    public static final int Club = 3;
    public static final int Heart = 4;
}

Intro OOP, Chapter 4, Slide 22