aspose file tools*
The moose likes Beginning Java and the fly likes diff b/w abstract classes and Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "diff b/w abstract classes and Interfaces" Watch "diff b/w abstract classes and Interfaces" New topic
Author

diff b/w abstract classes and Interfaces

Mallik Koppuravuri
Greenhorn

Joined: Jul 28, 2005
Posts: 2
hi ,

Can anybody explain what is the exact difference b/w abstract classes and Interfaces.
I read that both of them have just the declarations of the methods and no definitions of the methods. Then why do we have two different approaches for the same need.

I will appreciate if any body can quote some examples to explin this.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
This question is asked many time in java forum.
An abstract class can have different flavours of modifiers like public,private etc but in an interface the members can only be public.
A abstract class can have method definitions but an interface cant.
These are very basic difference.
Google for this topic you will get a lot more. The main thing we need to understand is where to use abstract class & where to use an interface.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Mallik Koppuravuri
Greenhorn

Joined: Jul 28, 2005
Posts: 2
Thank You . I will check the posts.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Perhaps the most important difference is that a class can directly extend only one other class, but it may implement any number of interfaces.


[Jess in Action][AskingGoodQuestions]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Mallik Koppuravuri:
hi ,

Can anybody explain what is the exact difference b/w abstract classes and Interfaces.
I read that both of them have just the declarations of the methods and no definitions of the methods. Then why do we have two different approaches for the same need.

I will appreciate if any body can quote some examples to explin this.


Also, the definition given for an abstract class is not quite correct. An abstract class CAN contain definitions of any (or all) of its methods, but an interface cannot.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: diff b/w abstract classes and Interfaces