Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

I think that this question expects more than syntactical or language dependent differences, and one should tell when to use interface and when to use abstract class.
The key notion behind use of interface is adhering to a contract. All the features of an interface are abstract, and it is the implementor's responsibility to implement those.
Abstract class can be used when atleast some functionality is concrete enough to be carried forward via inheritance. Most of the listener classes are abstract classes, which provide native functionality implemented.

- Learner September 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
4
of 4 vote

What is an Abstract Class?

An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.

What is an Interface?

An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.

*I voted on the other, this is just another explanation from codeproject

- brnr September 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Abstract class can not be instantiated where as in Interface class there is definition/implementation of API.

- SRB September 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The only difference is that: An abstract class can have instance methods that implement a default behavior.
If the requirement is such that you have to force a default behavior to all your classes. best way to to write that default instance method to an abstract class so that all classes extending this particular abstract class will have that default behavior.

- Sandip September 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The major difference between abstract class and interface is in case of abstract class we can say that its a partially implemented structure where an interface is fully unimplemented structure. Now taking consideration of other facts like all the variables declared in an interface are public static in nature as well as if we write any class also by default public static. No method can have body part. And in case of abstract class we may or may not put the body part of the methods. If we do not put any body part in the abstract method the it should have public abstract.

- deb September 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

interface is nothing but representation of the requirements in technical terms where as abstraction is trying to give implementation to the requirements. If my abstract try doesn't meet my requirement then i'll overrride else i've a reusable component.

- amit.yatagiri September 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

An Abstract class exhibits an "IS-A" relationship whereas an Interface exhibits a "HAS-A" relationship.

- SS October 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Abstract class can have have states (instance variable) while interface cannot have. Abstract class can have some method implemented while interface cannot have. Abstract class can have method overridden by only its subclasses while interface have can have its method implemented by all other classes that implements the interface. More?

- nixfish October 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Few more points apart from definition
- Abstract class is used to provide a default behavior, interface used to force to have specific behavior.
- Interface is used when the design changes frequently.

- balraj.techs February 01, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Abstract Class is @%$*()!@)_+=-][;./,
and
Interface is .,/;\][!)$*@+_=--

- ACI October 03, 2012 | 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