Interview Question for Software Engineer / Developers


Country: -
Interview Type: Phone Interview




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

A basic difference i can think of is that
* Interfaces are used at places when u don't know anything.
* Abstract classes are used in places when u know some components and do not know some. Everything that u do not know is made abstract.

- salvo4u May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The difference between an interface and an abstract class is, interface which is fully unimplemented structure an an abstract class is which partially implemented structure.

- deb May 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

When we want to leave implementation to 3rd party vendors then choose interface.
And when we have some common feature shared by all the objects then we choose abstract class.
Interface is always better when compared to Abstract class.

- Neelima May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Java !!! Well M not a very much of JAVA Coder unlike C++ but My Answer would be like.

Abstract Class in More flexible than interface . means, i will put some logic which later on I can change easily in the derived classes.. Well that says the saying " In interface by Default all methods are abstract". So only Definition in Interface.


However coming to this question. here both the implementation are more or less same. Except the fact that if I want a method Say get1() to have some bydefault logic, I can't do in interface, i need to have Abstact Class.
but along side I am okei with your rest of the responses !!!

- hprem991 May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If in a class there's is one abstract method(other methods might have body), then the class must be abstract.
But, all the methods of an interface must be abstract(i.e. none of the methods can have body). Interface can be thought as 100% abstract class

- Anonymous May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Your responses all are very valid. But what he might be looking is the purpose. If you want define the core abilities of your class use abstract classes, if you want to define the peripheral abilities of the class use interface. eg: AbstractList, vs Comparable, You can have a person class its core feature is not comparing but some other business logic, one of its ability is also that it can compare. On the other hand, a list is concrete implemention of absctract list, there isn't much else the list can/should do.

- prolificcoder May 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the main thing is, is the abstract class will not support multiple inheritence for any class extending it.

- Debashish May 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One can easily add new methods in the abstract class without requiring the subclasses to implement it. This is not possible in case of an interface. Code change required to add new methods can be very small for abstract class whereas in case of interface all the implementing classes have to be modified.

- Anand Nigam June 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The way I look at abstract classes is that they are just like other classes with 2 exceptions
1. They cannot be instantiated (biggest exception).
2. They can contain abstract methods.

The reason I use abstract class is when the class can have a lot of member functions that can be inherited by many classes but the class in itself has no meaning to instantiate it! Also they work like an "interface" in the sense that you can have abstract methods.

- axecapone June 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think that technically speaking the two are the same. As all the methods of the abstract class are abstracts (no base definition of any method), the abstract class is behaving like the interface ie subclassing MyAbstract will require to "implement" all three methods (as implementing MyInterface will require implementing the three methods).
Xali Beut

- xalibeut September 26, 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