AP® Computer Science A glossary
final
Also called: constant
Course: AP® Computer Science A Shows up in: Unit 3: Class Creation
A keyword that makes a variable's value unchangeable once it has been set.
Appears in the course and exam description (CED): 3.7.B.3
Assigning to a final variable after it has a value is a compile-time error. Constants are usually named in capital letters, such as MAX_PLAYERS.
public class Game
{
public static final int MAX_PLAYERS = 4;
public static void main(String[] args)
{
System.out.println(Game.MAX_PLAYERS);
}
}
Output:
4 Learn it properly, with a checkpoint 3.7 Class Variables and Methods