Results 1 to 2 of 2
  1. #1
    katturv is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default accessing a singleton class inside another class

    Public class Singleton

    {

    private static variable _instance ;

    public Singleton()

    public static getSingleton()

    {

    If( _ instance = null)

    _instance = new Singleton();

    }

    return _instance;

    }

    Now if i want to access this singleton class in another class

    Public class patient

    {

    /*

    * how to access the Singleton class here

    */

    Can we do like this::: Singleton s = new Singleton();?????????????here.......

    }
    how o access a singleton class inside another class???

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    11

    Default

    That issnt java code, many many syntax errors and so on.
    And do you understand singletons? Dou you understand the code? Call the getSingleton method!
    Singleton s = Singleton.getSingleton();

    Or use an enum :p

Similar Threads

  1. Singleton Thread safe class
    By userj2ee in forum Advanced Java
    Replies: 1
    Last Post: 08-13-2010, 06:32 PM
  2. Replies: 8
    Last Post: 03-21-2009, 10:34 AM
  3. Replies: 2
    Last Post: 10-06-2008, 10:06 PM
  4. Replies: 0
    Last Post: 02-17-2008, 10:03 AM
  5. Replies: 0
    Last Post: 02-17-2008, 10:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •