Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

C++ supports multiple inheritance of classes, Java (and C#) supports single inheritence of classes and multiple inheritance of interfaces.

When C++ added multiple-class inheritence pure OOP was thought to be "the" solution to everything.

In the meantime it was proven that class inheritance is good, but it ends up with tightly coupled systems. The more class inheritance you use, the more likely that one small change will have a huge impact on your entire system.

Loosely coupled inheritance - interfaces - are considered a much better option these days.

- Selmeczy, Péter February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

and multiple inheritance will lead to duplicated data.

- yezhuen February 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

"Loosely coupled inheritance - interfaces - are considered a much better option these days."


That depends on whom you ask. I wouldn't agree, and neither would the people that made Python, Scala, etc. It's completely true that there are some issues with multiple inheritance. It's not just about tightly-coupled systems, but also about the greatly increasing possibility of name conflicts, etc. There can (depending on implementation) be issues like the dreaded diamond problem, etc.

- eugene.yarovoi February 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

c++ supports multiple inheritance but java not.
i think that it is a disadvantage of java ,or may be to make the java easier to implement
inheritance.

- prashantkr.singh90 February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

check wikipedia Diamond_problem page, this is why java does not support multiple inheritance. also called Diamond of Death concept.

- Amitesh February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can someone offer us a complete answer?

- yingdi1111 February 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can someone offer us a complete answer?

- yingdi1111 February 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hmmm.. Lets see if this example makes sense.. "A" defines a method which returns the meaning of "Right" as in Will or Justice.. "B" inherits from A but overrides that method and returns the meaning as Direction.. Now, "C" inherits from A but overrides that method and returns the meaning as Correct.. Now, if D goes and inherits from both B and C (multiple inheritance).. there is no way to find which method to call if we want the meaning of right..

C++, provides multiple inheritance..
Java does not for the above reason.. :).. but you can achieve multiple inheritance through interfaces in java

- Sandeep February 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

C++ supports it; Java doesn't.


I think it's bad that Java doesn't support multiple inheritance, and I think that at times, that leads to bad design of certain aspects of Java programs. There are, however, certain difficulties with multiple inheritance that led the creators of Java to decide to not include that feature (look up "dreaded diamond problem" and the like).

- eugene.yarovoi February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not supporting Multiple inheritance in Java is not bad at all. Multiple inheritance can be achieved in Java using interfaces.

- Natesh February 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Perhaps, if you don't want any kind of code re-use with your multiple inheritance.

- Anonymous February 19, 2012 | 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