Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

interface and abstract class

Thread view: 
sandy - 21 May 2007 13:42 GMT
what is the main difference b/w  interface and abstract class.
in which situation we will use choose interface and abstract class
Lew - 21 May 2007 14:50 GMT
> 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

Richard Reynolds - 21 May 2007 23:19 GMT
> 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
Robert Mark Bram - 21 May 2007 23:54 GMT
> 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
:)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.