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

  • SEARCH
  • Home
  • 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 7439501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:42:56+00:00 2026-05-29T10:42:56+00:00

Before I ask the question I like to provide the code for clarity. Below

  • 0

Before I ask the question I like to provide the code for clarity. Below is my code for singleton class.

public class CoreData {

    private boolean VarA;

    private static CoreData instance = null;

    protected CoreData() {
          // Exists only to defeat instantiation.
    }

    public static CoreData getInstance() {
          if(instance == null) {
             instance = new CoreData();
          }
          return instance;
    }

    public  boolean getVarA(){
        return VarA;
    }

    public  void setFirstTime(boolean B){
        VarA = B;
    }
}

Now I have few questions to ask

  1. What will be difference if make the member variable VarA as static?
  2. Can I initialize the member variable in the method getInstance()?
  3. What is the best practice in initializing member variables in Singleton class?
  4. What is the meaning of making this class as final?
  5. What is the meaning of making the member variable final.

I am very new to java and OOPS. I am learning it now. I would be grateful if someone answer my queries to make my knowledge better.

  • 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-29T10:42:56+00:00Added an answer on May 29, 2026 at 10:42 am

    What will be difference if make the member variable VarA as static?

    It will be harder to make it non singleton later

    Can I initialize the member variable in the method getInstance()?

    Yeah. Why not. But actually constructors are done for this.

    What is the best practice in initializing member variables in Singleton class?

    By the best practice you should use some IoC and don’t put any code about scope in your logic code.

    What is the meaning of making this class as final?

    You should use private constructor instead of protected one or make it final to prevent creating several instances by extending. Like new CoreData(){};

    What is the meaning of making the member variable final?

    I believe all variables should be final by default. Also it can help you with multi threading issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, before I ask, i would like to point out that this question
This may seem like a weird question but thought I would ask here before
I have a model Question with a field called userid , before one ask
I have ask this kind of question before, but it seems my previous question
before I ask my question I wanted to let everybody know that I appreciate
Before posting my question, I would like to tell you that I have no
I have tried to ask a variant of this question before. I got some
Let me explain the situation before I ask the question. I have a site,
I tried to ask this question once before, but nobody understood what I want
I'm sorry if I ask a question that's been asked before, but I could

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.