This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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
Author

difference between abstract class and an interface

rafa
Greenhorn

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. http://www.javaranch.com/name.jsp
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 9.1.1.1 abstract Interfaces
-------------------------------
Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs.
Difference:
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.
Jamal.
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,
Corey


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between abstract class and an interface