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