What is the use of constant class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the use of constant class?

Why would we want to use constant objects? Could someone give me some examples where it might be useful? Edit: I understand the use of constant variables to hold constant values such as pi, but what about constant class?

5th Jul 2017, 5:57 PM
Handy
Handy - avatar
3 Answers
+ 2
Pi? Days of week? Months of year? etc... Anything that is constant and doesn't change - opposite of a variable.
5th Jul 2017, 6:01 PM
AgentSmith
+ 1
A way to make code easier is the most common. However, declaration of constants can be based on preprocessor directives. You may want to restrict a buffer size based on the platform, for example.
6th Jul 2017, 1:08 AM
Jamie
Jamie - avatar
0
It also saves a lot of memory as your program will know that this variable cannot be changed later on in the code.
29th Jul 2017, 11:13 PM
Abir Mohammad Razzak
Abir Mohammad Razzak - avatar