File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Interface" Watch "Doubt in Interface" New topic
Author

Doubt in Interface

jesintha jegan
Greenhorn

Joined: Jan 05, 2009
Posts: 17
Hi this is jesintha.Im a new member.Im preparing for SCJP 1.5 .

Can anyone tell me why we need interfaces apart from abstract classes?Becaz i read that interfaces are 100 percent abstract class.what is the difference between abstract class and interface?



Thanks in advance.


If you don't design your own life plan, chances are you will fall into someone else's plan.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3837

jesintha jegan wrote:Hi this is jesintha.Im a new member.Im preparing for SCJP 1.5 .

what is the difference between abstract class and interface?

Welcome to JavaRanch

Mainly interfaces can have only method definitions (as far as the methods are concerned). Abstract classes can have method implementations (which are non-abstract) and abstract methods (with no body, only method definitions). The rule is if you have at least one abstract method defined, the class should declared to be abstract.
You will find Sun tutorials useful to get started.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Interface are built to define contracts only. It will define what to do only, not how to do. And abstract classes can also define what to do, but it can also define how to do. Both promotes loose coupling. Make client codes independent to implementation. Client can only see interface's API, client does not know how that API is defined by the interface implementor, so in future you have flexibility to change interface's API definition, if any new and enhanced implementation you got. In programming world, change is constant, so interface make client's code independent of these changes.


SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in Interface