Flipkart Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

PLEASE SUGGEST A ANSWER...

- SUBHASHINI August 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In java it would be

static private ObjectType object;
 public ObjectType getInstance(){
   if(object!=null)return object;
   object = new ObjectType()
   return object; 
 }

- aathif.md August 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

With one line lesser;

static private ObjectType object=null;
 public ObjectType getInstance(){
   if(object==null)object = new ObjectType();
   return object;
 }

- devsathish March 16, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@aathif, your answer is not thread safe. The thread safe way to do it is

class ObjectType {
      class ObjectTypeHolder {
         public static ObjectType instance  = new ObjectType();
      }
      public static ObjectType getInstance() {
         return ObjectTypeHolder.instance;
      }
   }

This ensures the object is only created the first time it is requested, and no more than one instance of it is ever created (due to the locking of the ClassLoader while it's loading the Holder)

- Ran September 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

public class Singleton {
// volatile is needed so that multiple thread can reconcile the instance
// semantics for volatile changed in Java 5.
private volatile static Singleton singleton;

private Singleton()
{

}

// synchronized keyword has been removed from here
public static Singleton getSingleton(){
// needed because once there is singleton available no need to acquire
// monitor again & again as it is costly
if(singleton==null) {
synchronized(Singleton.class){
// this is needed if two threads are waiting at the monitor at the
// time when singleton was getting instantiated
if(singleton==null)
singleton= new Singleton();
}
}
return singleton;
}

}

- Anonymous September 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what's "signature"?

- Anonymous February 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Prototype of a function is usually called signature.

- neoX April 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Prototype of a function is usually called signature.

- neoX April 22, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More