Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract vs. Interface

 
Travis Gibson
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Fellow ranchers,
I have a few questions in regards to Abstract vs. Interface.
What exactly are the difference between the two. Except the fact that Interfaces can be used a Object types I really don't see the difference. So here 's my questions.
1.) Abstract - Class which implement Abstracts must provide impletmentation of all prototype methods in Abstract. Or the implementing classes become abstract themselves.
Ans. I think this is true
2.) The same as above applies for interfaces?
Ans. I think this is true also.

3.) Can an Interface have an static member?
Thanks in advance for all the help,
Malik
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Travis,
1. Yes, if a class extends an Abstract class it must be provide implementation for all the methods. If it does not it must declared as an Abstract class itself.
2. Yes. Any class implementing an Interface must override all the interface methods.
3. Yes. Interface variables are automatically public and static.
The main difference is that Interfaces guarantee a given behaviour BUT not how the behaviour occurs.
Abstract classes can contain a mix of fully implemented methods and empty methods ie there's usually only one or two the subclass needs to provide implentation on.
Hope that helps.
------------------
Jane
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic