I am making an online test web project using applets. I want to declare a variable of int type which keeps track of number of correct answers. So where is that variable required to be declared so that it can be accessed in all the frames?
I am making an online test web project using applets. I want to declare
Share
As others have mentioned, you can declare a global variable using
public static:Then to access and use this variable, any other code would merely have to import this class:
However, this use of global variables is generally frowned upon. OOP gives you lots of tools for dealing with problems, and you probably don’t need global variables for this specific case.
Here’s a good piece about avoiding global variables — why and how. Discussion:
Why Global Variables Should Be Avoided When Unnecessary:
Alternatives to Global Variables: