-2

Possible Duplicate:
What is the difference between an interface and abstract class?

What is the difference between an interface and an abstract class in Java? Why would I want to use one over the other?

Community
  • 1
  • 1
darkuzul
  • 63
  • 1
  • 1
  • 11
  • 3
    http://stackoverflow.com/questions/1913098/what-is-the-difference-between-an-interface-and-abstract-class – lockstock Apr 17 '12 at 05:36
  • 1
    Java is not an acronym nor is it stylized in all capital letters, so not quite sure why you've written "JAVA". – Corbin Apr 17 '12 at 05:37
  • Why people give me bad points when im asking a question and be polite with everyone ? – darkuzul Apr 17 '12 at 05:46
  • 1
    @darkuzul: you could have searched for similar questions already asked on this forum instead of posting a new question. – Shashank Kadne Apr 17 '12 at 05:48
  • I'm sorry im new i explained that this is my first post in my post but somebody deleted everything i wrote i dont understand why. – darkuzul Apr 17 '12 at 05:56

3 Answers3

3

An abstract class can contain implementations, but it is a class and you can only extend one class.

An interface just contains declarations no implementations and you can implement as many interfaces as you want.

If you don't need to implement any methods go with interfaces.

If you have to implement a method go with an abstract class, but consider having it implement an interface. This will allow you to use alternative implementations in cases where you can't use the abstract class for example due to the impossibility of multiple inheritance.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
0

Well its a very broad question, there are a lot of difference between them, it is impossible to discuss all of them here, you can google it to get good answers, but

Broadly speaking abstract class is a partially implemented partially unimplemented structure but interface is a fully unimplemented structure

Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125
0

Here is my explanation with some real life example which has been written 2 years ago -

http://karthikjcecs.wordpress.com/2009/01/14/java-interfaces-versus-abstract-class/

Hope it helps you understand better.

Karthik Ananth
  • 211
  • 1
  • 8