IT Community - Software Programming, Web Development and Technical Support

difference between abstract class and interface

This is a discussion on difference between abstract class and interface within the Java Programming forums, part of the Software Development category; Difference between abstract class and interface a) All the methods declared inside an interface are abstract whereas abstract class must ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-21-2007, 12:22 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default difference between abstract class and interface

Difference between abstract class and interface

a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract.

b) In abstract class, key word abstract must be used for the methods
Whereas interface we need not use that keyword for the methods.

c) Abstract class must have subclasses whereas interface can't have subclasses.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-23-2007, 10:41 PM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Cool Re: difference between abstract class and interface

  1. interface contains methods that must be abstract; abstract class may contain concrete methods.
  2. interface contains variables that must be static and final; abstract class may contain non-final and final variables.
  3. members in an interface are public by default, abstract class may contain non-public members.
  4. interface is used to "implements"; whereas abstract class is used to "extends".
  5. interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.
  6. interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces.
  7. interface is absolutely abstract; abstract class can be invoked if a main() exists.
  8. interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.
  9. If given a choice, use interface instead of abstract class.
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-27-2007, 09:19 PM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Re: difference between abstract class and interface

the main differences between an interface class and abstract class are

1.abstract classes must be given by keyword abstract,where as in interface class with key word interface

2.every method in interface class should be abstract,but this is not necessary in abstract class

3.by default what ever variables we decalre in interface are public static final,where as in abstract class they can be default and instance variables also
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between abstract class and interface srikumar_l C# Programming 0 12-17-2007 03:18 AM
List out all the similarities/difference between an Abstract class and Interface? H2o ASP and ASP.NET Programming 1 07-24-2007 03:16 AM
What’s the difference between an interface and an abstract class? Sabari Java Programming 1 07-17-2007 05:00 AM
interface extending a class vigneshgets Java Programming 0 05-22-2007 04:13 AM
Abstract Class nhoj Java Programming 1 05-08-2007 05:35 AM


All times are GMT -7. The time now is 11:00 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0