Amazon Interview Question for Software Engineer / Developers






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

You don't need to simulate multiple inheritance in C++; it is already a feature. Could the question be simulating it in another language where it is not allowed?

- barcod April 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question seems to be correct and make sense, not sure of java language - but java avoids multiple inheritance like C++ for simplicity reasons.

And multiple inheritance in Java can be achieved by using multiple inheritance of interfaces. Things may have changed since I touched java - 10 years back.

- srinivas April 17, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Multiple inheritance is not possible in java as it lead to ambiguity. For instance you have a class Drive, and it has 2 child classes CD_Drive and DVD_Drive. The drive class has a method burn (), which is inherited by the child classes CD_Drive and DVD_Drive. Now, lets say we have another child class, Combo_Drive which is inherited from both Cd_Drive and DVD_Drive ( This is multiple inheritance), Now the problem is which burn() version should the burn() should Combo_Drive Inherit, CD_Drive one or the DVD_Drive one. SO, to avoid this ambiguity java does not allow multiple inheritance.
But at times we need dual behavior. Like we want the combo drive to have the behavior of both cd_drive and dvd_drive. So, we can actually inherited from one of the classes, let say cd_drive and form a single level inheritance, which is valid in java and at the same time create and interface for that represent the other class which is the dvd_drive. Finally we can say class Combo_Drive extends cd_Drive and Class Combo_Drive implements dvd_Drive. Doing this we have incorporated the behavior of both cd_drive and dvd_drive in combo drive.

I tried to explain the solution to the best of my knowledge. I hope it helps!

- Miss N April 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In order to provide the functionalities of multiple inheritance in java , we have interfaces , and you can implement more than one interfaces , read about the same . Complete Reference is a good place to look for it.

- Abhik April 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ofcourse, you do have multiple inheritance for interfaces, but interfaces are only useful when they are implemented by classes. So, the main question here is how would you simulate multiple inheritance in java since you do not have multiple inheritance between classes. Then we can say using interfaces.

- Miss N April 22, 2011 | 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