logo
Учебник_ПОА

Constants

A constant is another type of field. It holds a value that is assigned when the program is compiled, and never changes after that. Constants are declared using the const keyword; they are useful for making your code more legible.

const int speedLimit = 55;

const double pi = 3.14159265358979323846264338327950;

A readonly variable is like a constant but its value is assigned when a program starts up. This allows you to set the value based on some other condition that you don't know until the program is running. But after that first assignment, the value cannot change again while the program is running.