Google Interview Question for Software Engineer / Developers






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

to create copies of the object

class person{
String name;
int age;

public person(){
}

public person(person p)
name=p.name;
age=p.age;

}

person(person) is copy consructor

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

it's C++. In C++ copy constructor often used inside stl. For example when stl::vector needs to resize it allocates new memory block and calls copy constructor for each object in container to perform copy from old to new memory block.

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

1) when an object passed by value to a function
2) when an object is returned by value from a function
3) in cases like:
Sample object2 = object1;
Sample object2(object1);

- avadh.786 September 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

no... the cases 1 and 2 operatoroverloading of ==.does the job of assigning.
copy constructor is called when an object is created and its parameter is an object of same type

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

sorry operatoroverloading of = instead of ==

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

From wikipedia,

The following cases may result in a call to a copy constructor:

1. When an object is returned by value
2. When an object is passed (to a function) by value as an argument
3. When an object is thrown
4. When an object is caught
5. When an object is placed in a brace-enclosed initializer list

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

Also when you are creating a new object from an existing object.

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

Copy constructor is called when:
1) An object is passed to a function by value
2) Object is returned from a function by value
3) Create a new object from an existing object
4) In containers like vector, when the re-sizing of vector happens.

- sandeep April 29, 2012 | 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