Interview question advice: What’s the difference between an interface and an abstract class

I met a recent CS graduate last week who was wondering the right way to answer “What’s the difference between an abstract class and an interface”. In his case, the question was in a Java context, but this applies to C# (and other .NET languages).

Here are the keys to answering a question like this:

1. You need to actually know the correct and complete technical answer

I’m not going to get into a detailed analysis of the difference. There are a few StackOverflow answers that are worth reading if you don’t understand. I will say that this question is fairly basic, and if you don’t have a firm grasp of the answer, you should do more than just read some websites — write code that uses interfaces and abstract classes and really try to internalize the difference. Look at examples of both in the standard library and think about the difference it would make if an interface was changed to an abstract class or vice versa.

2. Understand why the interviewer is asking the question

If I ask this question, it’s usually during a pre-screen. Since I believe the question is basic, I just want to make sure that the candidate meets a minimum qualification to be asked hard questions. Given that, I expect a fairly quick and smooth delivery of the answer. I never need perfection, but I don’t expect much struggling with this concept.

But, the real reason I ask questions like this is to see how the candidate explains technical concepts. I want to see that they know how to organize their thoughts and express themselves clearly. Nearly every programming job ad says something about spoken and written communication being important; it’s on the interview that you show that you have this skill.

3. Be able answer beyond the basics

You should know the mechanical differences like syntax and limitations of each, but if you stop there, you have only given a minimally correct answer.

A better answer follows this basic recipe

  1. Explain how they are the same (differences are only interesting if there are similarities)
  2. Explain the mechanical differences
  3. Explain when one is better than the other — then explain when the other is better
  4. Give concrete examples from your work or the standard library. Pick an example where the choice isn’t obvious, and work in your best project.

By the way, this works for any “What’s the difference …?” question.