• 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

What is the difference between interface and abstract class?

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as titled
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the abstract class has one or more abstact method while in interface we have all the methods public and abstract by default. the data members in a class can be or can not be final but in interface they are final by default. one thing more u can implement more then one interface in a class but cant exteng more then one abstract class.
this was all wht i know abt that
may this helps u
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found that a bit of a mouthful so I'll paraphrase:
An interface provides the default behaviour for a class without defining how any of that behaviour is implemented. (any class that implements java.lang.Comparable is guaranteed to have certain methods, but there is no specification on how those methods work)
An abstract class can also define the default methods for a class but can also implement some default behaviour for some of those methods. (java.io.InputStream defines the minimum methods an InputStream should have, as well as providing some default code for some of them)
Hope this helps. Interfaces and Abstract classes are important but a bit difficult to get your head around.
Dave
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The data members are also implicitly static, along with final, in an interface.
Along with everything Samer said, interfaces may also extend multiple superinterfaces, where as an abstract class is restricted to extending only one superclass. This allows for "multiple interface inheritance", so any class that implements an interface also implements all of the superinterfaces.
Basic thing to remember is abstract classes can have implementation, interfaces cannot.
Jason
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstract classes can generally provide what you would consider 'logical' inheritance.
e.g. vehicle > car or mammal > dog
Interfaces can provide links between hugely dissimilar classes.
e.g. in a drawing application an interface Drawable might be implemented by classes such as Triangle, EarthMover and Fish.
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Colin. i need that visual cue in order to grasp these kinds of things. then, it's off to the races i go.
if i understand correctly, is an abstract class like a template of a class, only that the actions that objects of the class perform are not defined?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic