wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Abstract vs. Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract vs. Interface" Watch "Abstract vs. Interface" New topic
Author

Abstract vs. Interface

Travis Gibson
Ranch Hand

Joined: Oct 17, 2000
Posts: 100
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

Regards,<BR>Travis M. Gibson, SCJP<BR>Java Developer<BR>www.travismgibson.com<BR>travis@travismgibson.com
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Abstract vs. Interface
 
Similar Threads
Abstract class vs Interface
Interface vs AbstractClass
Abstract class vs Interface
Abstract Classes Vs Interfaces
interface and abstract