Amazon Interview Question for Jr. Software Engineers


Country: United States




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

Line 5 : Cannot make a static reference to the non-static field y

- Vir Pratap Uttam April 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

and signature also static void f2()

- Kamal April 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int y = 9;

or

public f2(){y=35; }

or

public static f2() { (new a()).y = 35;}

- Anonymous April 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

y needs to be a static variable.

- SK April 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class a{

public int x = 7;
public int y = 9;

void f1(){
x=24;
}
void f2(){
y =35;
}
}

- lparka123 April 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

two parts will prevent any compiling:

void static f2(){y=35;}

should be

static void f2(){y=35;}

That's just testing if you know the syntactic restrictions of the language.

Also, y must be declared as a static variable, as it must be instantiated on compile to be accessible via operation from f2.

Additionally, just nit-picking on style, but the class should have its first letter of the name capitalized (A in this case)

- Javeed April 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The correct way is:

class a
{
public:
int x = 7;
static int y;

void f1()
{ x = 24; }
void static f2()
{ y = 35; }
};

- sergey.a.kabanov April 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can not access reference variable in static method

- Anonymous April 17, 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