File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes difference between abstract class and an interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "difference between abstract class and an interface" Watch "difference between abstract class and an interface" New topic

difference between abstract class and an interface


Joined: Feb 13, 2002
Posts: 6
What is the difference between abstract class and an interface
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Rafa, please note that JavaRanch has a naming standard.
Please update your display name.
As to your question, it has been asked quite a few times. Why not try a search in this forum?

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
JLS abstract Interfaces
Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs.
Abstract class is a simple class which may have undefined(with declaration only) methods. You can extend only one abstract class.
Interface is not a class-It's a special "type" in Java. You can extend(implement) more than one interface.
That's the difference. You can read RHE or Khalid Mughal's book for additional info.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
As was mentioned, you can do a seach in this forum and find a lot of information on this.
In short, however, an abstract class, unlike an interface, can contain non-abstract methods. In fact, an abstract class need not have any abstract methods. This means that classes that extend an abstract class can inherit fully functional methods, rather than reimplementing them at every level. This can be very useful for classes that share identical functionality. Also, abstract classes can contain instance variables, whereas interfaces only contain final static members. Take the following example:

Had this been implemented with an interface, both of the subclasses would have had to define identical code for the setName and getName methods. Also, the name variable itself would have been a static member, which is probably not what you would have wanted as all Americans would have the same name and all Germans would have the same name.
Unfortunately, Java does not allow multiple inheritance. Therefore, you can only extend one class, but you can implement multiple interfaces.
I hope that helps,

SCJP Tipline, etc.
I agree. Here's the link:
subject: difference between abstract class and an interface
It's not a secret anymore!