• Post Reply 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between Interface and Abstract class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone tell me the exact difference between interface and abstract class?
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rajapratap,
In an interface, all the methods should be (implicitly) abstract methods.
In an abstract class, you can have implemented methods also. Apart from them, you can have abstract methods. You would wonder (if you haven't realised before), you can have an abstract class without any abstract methods!!
These are the major differences.
The minor differences being,
In an interface, all the variables declared are implicitly static and final, but not so in an abstract class.
In an interface, all the methods are public, but not so in an abstract class.
Hope this helps,
Regards,
Suresh.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajapratap,
Here are some of the attributes of an interface:
1. Interface is basically a collection of abstract method definations and constants - no instance variables and no methods implementations. All the variables must be public, static, final.
2. Interface provide much of the functionality of multiple inheritence.
3. Interface is a skeleton of a class. The class while implementing an inetface must define and implement those methods.
4. Declarations are always public even if they are not mentioned.
Attributes of abtract class:
A class that is declared abstract that may not be instantiated. A class must be declared abstract under the following condition:
1> Contain one or more abstract methods.
2> inherits abstract method for which it does not provide implementation.
3> implements an interface but does not provide implementation for every method.
Regards,
Milind
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rajapratap:
Can anyone tell me the exact difference between interface and abstract class?


To be little precise with..
Interface are the most beautiful and powerful component provided by Sun people.
To get the utility of an Abstract class one has to extend it.. and that forms a heirarchy. Usually the utility of an abstract class persist with one heirarachy... (or we can abstract out the common functionality of a perticular heirarachy and put it in abstract class).
Where in case with Interface.. it has nothing to do with any class heirarachy.. things which you find common amongst all heirarchy can be put in interface.
Thats the greatest thing I belive. !!!
- Keyur
 
reply
    Bookmark Topic Watch Topic
  • New Topic