Amazon Interview Question for Software Engineer / Developers






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

Let’s take up this question in design point of view. Usually go for an abstract class when you have a set of classes having a common behavior. That abstract class can contain methods which are common for all the concrete classes which extend from it and have other methods implemented in their own way. For example, consider an abstract class Person; this class can be inherited by Jerry, Thompson and Verica. Because all three are human beings, they have certain features common to all human beings like hands, legs, head, neck etc, and they also differentiate themselves from others in terms of their own behavior (character). Go for interfaces when you want role specific behavior. In the above example, a person may perform multiple roles. For instance, Jerry may have roles such as Doctor (by profession), Father (to his children), Husband (to his wife) etc. Now we can have Doctor, Father and Husband as interfaces implemented by Jerry.
Code to an interface than an implementation
You would have come across the above quote many times. Here the word interface doesn't actually mean the interface in java. It just means coding to a super type than to the concrete sub type. It may be implemented either using interface or abstract class based on requirement.
To conclude, use abstract class and interface based on requirement (or design) and not for sake. Always think in terms of design than implementation. When they are used effectively, it improves code maintenance and re usability.

- ChandraValli January 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

worth appreciating the answer and approach. keep it up!

- spiderman August 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

While the purpose of Interface and Abstract Class are same, Abstract Class can have implementation of the method and also fields. An Interface cannot have implementations of the method or any fields. And a class can extend only one Abstract Class, but can implement multiple interfaces.

- Anonymous June 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Both interfaces and abstract class are used to establish contract with client code.
Use abstract classes when you have some code which can be reused by subclasses. So its like a template.When there is nothing reusable use interfaces.

- dhrubo July 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

interface allows multiple inheritance but Abstract Class does not

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

a 100% abstract class is a interface. :)

- ekapil2 November 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

a 100% abstract class is a interface.

>> Not exactly, abstract class cannot have be used when the subclass have already inherited from another class. In that case interface is the only option.

- Sancho Sebastine May 31, 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