what is the main difference b/w interface and abstract class.
in which situation we will use choose interface and abstract class
> what is the main difference b/w interface and abstract class.
> in which situation we will use choose interface and abstract class
<http://java.sun.com/docs/books/tutorial/java/IandI/index.html>

Signature
Lew
> what is the main difference b/w interface and abstract class.
> in which situation we will use choose interface and abstract class
Generally abstract classes are used for inheritance of (at least some)
implementation.
Interfaces are used for inheritance of type.
Another thing to note is that, in Java, you can extend only one class while
you can implement multiple interfaces.
Of course this is a massive simplification, there are many other factors to
take into account, mostly to do with OO design.
Tom Hawtin - 22 May 2007 00:20 GMT
> Another thing to note is that, in Java, you can extend only one class while
> you can implement multiple interfaces.
That's not necessarily to say that makes interfaces better than abstract
classes. Using an abstract class allows the compiler to detect
impossible casts. Multiple inheritance (of interface) tends to indicate
bad design (IMO).
In reality, (pure) abstract class or interface makes no significant
difference to client code. The main advantage of interface is that the
code is cleaner (doesn't require public abstract on methods of public
static final on fields). It also signals an intent that the type is
contains no implementation.
Tom Hawtin
> what is the main difference b/w interface and abstract class.
> in which situation we will use choose interface and abstract class
To add my own 2 cents..
Interfaces define ONLY abstract methods i.e. methods with no
implementation.
Abstract classes can define abstract methods and concrete methods i.e.
methods with an implementation.
A class EXTENDS an abstract class.
A class IMPLEMENTS an interface.
A class can only extend one class, but can implement many interfaces.
Rob
:)