Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6847563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:45:36+00:00 2026-05-27T00:45:36+00:00

I am making an online test web project using applets. I want to declare

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:45:37+00:00Added an answer on May 27, 2026 at 12:45 am

    As others have mentioned, you can declare a global variable using public static:

    public class MyClass {
    
        public static int globallyVisibleInt = ...;
    
        // or
    
        private static int visibleThroughAccessors = ...;
    
        public static void messWithGlobalState(int newValue) {
            visibleThroughAccessors = newValue;
        }
    
        public static int seeGlobalState() {
            return visibleThroughAccessors;
        }
    
    }
    

    Then to access and use this variable, any other code would merely have to import this class:

    // this code is inside another class and package
    MyClass.globallyVisibleInt++;
    
    // or
    MyClass.messWithGlobalState(14);
    

    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:

    As with all HeuristicRules, this is not a rule that applies 100% of the time. Code is generally clearer and easier to maintain when it does not use globals, but there are exceptions. It is similar in spirit to GotoConsideredHarmful, although use of global variables is less likely to get you branded as an inveterate hacker.

    Why Global Variables Should Be Avoided When Unnecessary:

    • Non-locality
    • No Access Control or Constraint Checking
    • Implicit coupling
    • Concurrency issues
    • Testing and Confinement

    Alternatives to Global Variables:

    • ContextObject
    • Stateful Procedures
    • Singleton Pattern
    • Hidden Globals
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an online C++ test question, which has been done. #include<iostream> using namespace
I'm making an online EOT converter... What 'Content-Type' header should I set to serve
I'm planning on making my (family) photo collection available online. I want to use
I am making a web application using php, and I would like to implement
I'm making an Online Library Management System using ASP.NET (with C#). So far everything
I'm making an online form for customers and now adding a submit button which
When making color choices during web design, I use free online tools such as
I am looking for some (preferably) online tutorials on making controls with 'Rich design-time
Making echo of a question around the web: Is the syntax for svn:ignore patterns
Making an adobe flex ui in which data that is calculated must use proprietary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.