Skip to content
Advertisement

How can I create and populate a constant from a file? [closed]

I’m making a word game program which has a dictionary of words in a text file. I need to run 2 methods through the dictionary in a single run by having a user choose options 1 and 2, then 3 to close. I need to make the dictionary a constant called DICTIONARY which is new to me.

Currently, in my program I have just opened the file and printed the contents before displaying the menu which option 1 and 2 are the methods that will play a small game which I am yet to code. Before I can start method 1 and 2 I need to create the DICTIONARY constant.

JavaScript

Advertisement

Answer

static and final key words can be used on a class variable to make it behave like a constant.

  1. The static modifier causes the variable to be available without an instance of it’s defining class being loaded

  2. The final modifier makes the variable unchangeable

For example:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement