Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

What is difference between an Interface and an abstract class

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello everybody,
I am preparing for the scjp exam,can anybody tell me the difference between interface and an abstract class,i am just confused.Please help me.
regards
vasanthi
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello,
Here is difference between Interfaces and Abstract Class
1. Interfaces can't have any method implementation, where as Abstrcat class can have method implementation.
2. Abstract class must be inherited, and give implementation for methods declared abstract, otherwise the derived class must be also declare Abstract, whereas Interfaces and implemented by class(implements iterface_name). If class implements any interface, it must give implementation for all method declared in Iterface.
3. A class can on extend from only one Abstrcat class(or concrete class), but a class can implement 2 or more Interfaces
4. Interfaces helps in adding types to class, this is not with abstract class.
5. Interface can be used to establish relation between unrelated class.
6. Interface helps in writing future safe code, it also facilites
writing generic code.
Though there is no method implemented in interface, it is very helpful. There is some thing called Tagging Interface which do not have any method, it just helps in marking the class for that interface. e.g. Serializable is tagging interface with no method.
Regards,

Sujit

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi! Vasanthi
An abstract class can have non abstract methods where as in an interface all its methods are abstract by the virtue of the fact that an interface only defines method prototypes and not their implementation
Hope this helps.

Originally posted by vasanthi:
Hello everybody,
I am preparing for the scjp exam,can anybody tell me the difference between interface and an abstract class,i am just confused.Please help me.
regards
vasanthi


 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Vasanthi,
Didn't you post the same question here?? Since these two are duplicate threads, I am going to close this one and invite others to continue the discussion, if need be, in the old thread.
Thanks!
Ajith
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic