Credit Suisse Interview Question

Embed Size (px)

Citation preview

  • 7/28/2019 Credit Suisse Interview Question

    1/2

    Credit Suisse Interview Question for Analysts

    0

    of 0 votes

    4AnswersImplement a class using singleton pattern

    - Singleton on November 12, 2008Report Duplicate|Flag

    Credit Suisse Analyst C

    Email me when people comment.

    0

    of 0vote

    ummm just look it up?

    public class Singleton {

    private static Singleton instance = null;

    private Singleton() {}

    public Singleton getInstance() {

    if (instance == null)

    instance = new Singleton();

    return instance;

    }

    }

    - Anonymous on November 14, 2008 |Flag

    Reply to Comment

    0

    of 0vote

    How to make it thread safe ?

    - Amit on July 29, 2009 |Flag

    Reply to Comment

    0

    of 0vote

    get that static instance to initialise staticly instead of lazily...

    do

    http://www.careercup.com/question?id=65087http://www.careercup.com/question?id=65087http://www.careercup.com/question?id=65087http://www.careercup.com/reportduplicate?id=65087http://www.careercup.com/reportduplicate?id=65087http://www.careercup.com/reportduplicate?id=65087http://www.careercup.com/flagquestion?id=65087http://www.careercup.com/flagquestion?id=65087http://www.careercup.com/flagquestion?id=65087http://www.careercup.com/page?pid=credit-suisse-interview-questionshttp://www.careercup.com/page?pid=analyst-interview-questionshttp://www.careercup.com/page?pid=c-interview-questionshttp://www.careercup.com/page?pid=c-interview-questionshttp://www.careercup.com/flagcomment?id=64901http://www.careercup.com/flagcomment?id=64901http://www.careercup.com/flagcomment?id=64901http://www.careercup.com/flagcomment?id=173895http://www.careercup.com/flagcomment?id=173895http://www.careercup.com/flagcomment?id=173895http://www.careercup.com/flagcomment?id=173895http://www.careercup.com/flagcomment?id=64901http://www.careercup.com/page?pid=c-interview-questionshttp://www.careercup.com/page?pid=analyst-interview-questionshttp://www.careercup.com/page?pid=credit-suisse-interview-questionshttp://www.careercup.com/flagquestion?id=65087http://www.careercup.com/reportduplicate?id=65087http://www.careercup.com/question?id=65087
  • 7/28/2019 Credit Suisse Interview Question

    2/2

    privatestatic Singleton instance =new Singleton();

    and the getInstance just returns 'instance'. That way you're removing all multithreading concerns

    from the singleton mechanism.

    - Sam on October 11, 2009 |Flag

    0

    of 0 votes

    What if there are other variables that need to be present in this class (which is usually the case) and need to be

    initialized in the constructor. In that case with what values will you initialize the singleton instance statically?

    -Apurvaon February 06, 2012 |Flag

    http://www.careercup.com/flagcomment?id=213776http://www.careercup.com/flagcomment?id=213776http://www.careercup.com/flagcomment?id=213776http://www.careercup.com/user?id=12189693http://www.careercup.com/user?id=12189693http://www.careercup.com/user?id=12189693http://www.careercup.com/flagcomment?id=12593674http://www.careercup.com/flagcomment?id=12593674http://www.careercup.com/flagcomment?id=12593674http://www.careercup.com/flagcomment?id=12593674http://www.careercup.com/user?id=12189693http://www.careercup.com/flagcomment?id=213776