Microsoft Interview Question for Software Engineer / Developers






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

doesnt look like a Microsoft question !!!

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

koi to answer do

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

koi to answer do

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

It took me a while to understand this. By default B[0] , [1] and [2] are null. When you initialize the array, corresponding objects constructor is not called. Hence mentioned line cause nullpoiterassignment exception.

- Master February 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In method gen(), before assigning value C1.B1[0].x=5, first assign an object to location B1[0]. working gen() method is as follows:

static void gen(c C1)
{
C1.B1[0]=new b();
C1.B1[1]=new b();
C1.B1[2]=new b();
C1.B1[0].x=5;//bug in the line
C1.B1[1].x=6;
C1.B1[2].x=7;
}

- sur February 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yep sur is right, when we declare an array of object, we have to redefine each element separately and also i think x should be declared static since we are directly using it with the class name, can anybody confirm that

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

it is not class, it is the reference variable

- tetura February 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The problem is in class C
class c
{
b B1[]=new b[3];
}

when class C is instantiated, 3 new reference variables are created (in stack), but they don't point to any object(in heap). So C1.B1[0].x will throw npe

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

true.....

- chandan.here4u May 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

class c
{
b B1[]={new b(), new b(),new b()};
}

I suppose, this will solve the problem.

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

nullpointexception

- Anonymous January 27, 2015 | 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