Google Interview Question for Software Engineer / Developers






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

1. singlton (of course, one can use non-member funcions too to create singlton)
2. to forbid to create objects on stack
3. automatic count amount of created objects and save it in private static data member and get the value of it by use of static member function

ideas have finished...

- columbo October 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

internal linkage

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

why do you mean by singleton?

- Anonymous November 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Primarily to facilitate shared usage of a common resource....
Could not understand how it was useful for singleton though...

- Anonymous November 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

-Singleton
-Utility Classes
-Factory Methods

Instance methods are instance methods because they rely on the state of the specific object instance.Any method that is independent of instance state is a candidate for being declared as static. The behavior instigated by a class method does not rely on the state of a particular instance. In fact, a static method cannot rely on an instance's state since static methods lack access to this reference. Instead, the behavior of a class method either depends on a state that all objects share at the class level, or is independent of any state at all.

javaworld.com/javaworld/javaqa/2001-11/03-qa-1121-mrhappy.html?page=1

- amit November 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Singleton - It is a design pattern used when we want to have only one instance of a class to be returned. e.g. someone asks for a connection to an instrument. Every time a person asks for a connection we would return the same instance we created.

In that case we can define an object as static (which would mean only one instance exist throughout the scope) and define the constructor as private so that no other method can create an instance of the class.

Apart from that static would be used for counter purpose.

- Anonymous December 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Static member function can be used when creating new thread to run a member function.

class a {

- Haoju Ho May 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry, didn't finish in the original reply.
In PThread library, a normal function (i.e., not non-static-member-function) has to be provided as the parameter of pthread_create(). In this case, a static member function of the class of subject is useful.

class A {
public:
  static void* thread_run(void *obj);
  
private:
  void doSomeWork();
}

void *
A::thread_run(void* obj)  {
   A*  ap = static_cast<A*>(obj);
   ap->doSomeWork();
}

void
main() {
  A a_obj;
   pthread_t  thread_1;

    pthread_create(&tthread_1, NULL, (void* (*)(void*))&A::thread_run, static_cast<void*>(&a_obj));
}

(actually, the doSomeWork() function doesn't need to be a member of A, and the passed in object doesn't need to be class A, but the thread_run function has to be a static member function, if it needs to belong to some class)

- Haoju Ho May 01, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. singleton class would need a createInstance method, a static method of a class
2. overloading new and delete operators
3. a method needed to operate on static members (member shared by all objects of a class)

- confused_banda November 16, 2013 | Flag Reply


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