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

    Default use of private in getter and setter

    1.use of private variable in getter and setter method??
    2. how to implement singleton class in another class??
    like
    public class Singleton {
    // class is automatically instantiated when the
    // class is loaded
    private static Singleton instance = new Singleton()

    // constructor is made inaccessible by declaring
    // it private
    private Singleton() { ... }

    // Access to the single instance of the class is
    // provided by a static accessor method
    public static Singleton getInstance() {
    // returns a reference of the private instance
    return instance;
    }

    // rest of the class implementation
    }
    i have one more class...how to use singleton class inside this???
    class B
    {
    }

  2. #2
    javanb is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by katturv View Post
    i have one more class...how to use singleton class inside this???
    Create a public getter for private variable 'instance' in A, then call that getter from B.

Similar Threads

  1. Replies: 2
    Last Post: 11-16-2010, 06:51 PM
  2. Replies: 7
    Last Post: 06-28-2010, 08:52 AM
  3. private static setter method problem
    By kyussy in forum New To Java
    Replies: 7
    Last Post: 01-27-2010, 05:02 PM
  4. Replies: 4
    Last Post: 01-01-2009, 01:03 PM
  5. problem in getter method
    By freddieMaize in forum Advanced Java
    Replies: 5
    Last Post: 05-26-2008, 08:02 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
  •