This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Interface" Watch "Doubt in Interface" New topic

Doubt in Interface

jesintha jegan

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

Joined: Mar 24, 2008
Posts: 3902

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.

[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.

I agree. Here's the link:
subject: Doubt in Interface
It's not a secret anymore!