Interview Question for Software Analysts


Country: India




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

Seems is not, nothing is pointed to a n A object reference since that may getA is may pointed to null

- Uriel Rodriguez February 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Only pointers can be null. As static object B::a was constructed by default CTOR even prior main().

You can see this line:
A's constructor called.

- Anonymous February 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

since "A a " is a static object, so first all static objects are constructed.

- sanjay February 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Copy of static object B::a will be constructed and returned from b1.getA(). This was copy CTOR will be called.

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

But in the line "A a1 = b1.getA(); " the copy of static object returned is copied in "a1" object , and first a1 object should be constructed using a default constructor of class A, correct me if i am wrong

- sanjay February 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Theoretically, temporary object will be created and returned from b1.getA(), and then in "A a1 = b1.getA();" copy CTOR will be called again to construct a1.

In practice creation of temporary object will be optimized by compiler.

What you describe is operation of assignment operator (CTOR can't be called twice):
A a1;
a1 = b1.getA();

- Anonymous February 17, 2014 | 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