interface and abstract class

  • Follow


what is the main difference b/w  interface and abstract class.in which situation we will use choose interface and abstract class
0
Reply gaddamsandeeps (4) 5/21/2007 12:42:43 PM

sandy wrote:> 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>-- Lew
0
Reply Lew 5/21/2007 1:50:50 PM


"sandy" <gaddamsandeeps@gmail.com> wrote in message news:1179751363.439939.291710@z28g2000prd.googlegroups.com...> 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.
0
Reply Richard 5/21/2007 10:19:28 PM

On May 21, 10:42 pm, sandy <gaddamsande...@gmail.com> wrote:> what is the main difference b/w  interface and abstract class.> in which situation we will use choose interface and abstract classTo add my own 2 cents..Interfaces define ONLY abstract methods i.e. methods with noimplementation.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:)
0
Reply Robert 5/21/2007 10:54:40 PM

Richard Reynolds wrote:> > 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
0
Reply Tom 5/21/2007 11:20:47 PM

4 Replies
93 Views

(page loaded in 0.092 seconds)

Similiar Articles:













7/21/2012 5:35:46 AM


Reply: