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 9129307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:42:58+00:00 2026-06-17T07:42:58+00:00

If I defined Class ‘A’ as a Singleton mean I am able to create

  • 0

If I defined Class ‘A’ as a Singleton mean I am able to create only one object of the class ‘A’. If I made it as Serializable and serialized it then How can i achieve the Singleton state of same object?

  • 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-06-17T07:42:59+00:00Added an answer on June 17, 2026 at 7:42 am

    Quoting Effective Java #77, you should look at implementing readResolve method.

    The readResolve feature allows you to substitute another instance for the one
    created by readObject [Serialization, 3.7]. If the class of an object being deserial-
    ized defines a readResolve method with the proper declaration, this method is
    invoked on the newly created object after it is deserialized. The object reference
    returned by this method is then returned in place of the newly created object. In
    most uses of this feature, no reference to the newly created object is retained, so it
    immediately becomes eligible for garbage collection.

    public class Elvis implements Serializable {
    public static final Elvis INSTANCE = new Elvis();
    // readResolve for instance control - you can do better!
    private Object readResolve() {
    //Return the one true Elvis and let the garbage collector
    // take care of the Elvis impersonator.
    return INSTANCE;
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i defined one class to create cookie by received parameter's from user. when
While you create a user defined class in Java, you do not specify it
I made my class immutable by following all java standards A. Defined class as
I have script with defined class (for instance, Singleton.php). This class implements classic singleton
I have a user defined class that I want to create a public List
I have defined class template named CallBackAtInit which only purpose is to call a
I have a collection of user defined class object, e.g. Car instances, what is
Program has more than one entry point defined: 'Class.Main()'. Compile with /main to specify
I want to invoke a method of an object from user defined class for
I've defined Class A which has number of methods. Then I have this other

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.