File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Difference between Abstract Class  and Interface, Which scenarios we are using both? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between Abstract Class  and Interface, Which scenarios we are using both? " Watch "Difference between Abstract Class  and Interface, Which scenarios we are using both? " New topic
Author

Difference between Abstract Class and Interface, Which scenarios we are using both?

Koti Samadhi
Greenhorn

Joined: Aug 26, 2009
Posts: 29
Difference between Abstract Class and Interface, Which scenarios we are using both?

Any one can , Please reply with examples.

Thanks
Koti
Anu satya
Ranch Hand

Joined: Mar 17, 2005
Posts: 146
Abstract class can also have non-abstract methods in it. but, interfaces can't have non-abstract methods.

Abstract class can have constructors where as interfaces can't have constructors

Abstract class can be extended to only one sub class....(Single inheritance) where as you can implement multiple interfaces

bot abstract classes and interfaces can't be instantiated.

Regards,
Anu






With Regards,
Anu
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Koti Samadhi wrote:Difference between Abstract Class and Interface, Which scenarios we are using both?

Hi Koti,
Both expose the concept "Abstraction". Abstract classes are useful when you need to provide a common set of method implementation(s) for all the subclasses to share. Most modern frameworks build around the concept of interfaces.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Santhosh Reddy
Greenhorn

Joined: Sep 25, 2006
Posts: 27
Purpose of both abstract class and interface is almost the same, except you can use abstract class when some of the implementation is fixed(few methods are implemented) and rest of the implemtation is left to the user.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Santhosh Reddy wrote: . . . and rest of the implemtation is left to the user.
Probably better to say "and the rest of the implementation will be different in the subclasses."
s.palanivel rajan
Ranch Hand

Joined: Sep 22, 2009
Posts: 40
hi this is simple....
In Interface only abstract and public access specifiers are allowed...
In abstract classes all normal access specifiers are allowed..
abstract classes should not be instantiated..
Use abstract keyword for abstract classes..
Use interface keyword for interfaces..



With Regards,
S.Palanivel Rajan B.E.
Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
s.palanivel rajan wrote:hi this is simple....
abstract classes should not be instantiated..
[/color]


Do you mean that if you want you can but you should not ?

s.palanivel rajan wrote:


cool yaar. from where you have picked up these habits ?
s.palanivel rajan
Ranch Hand

Joined: Sep 22, 2009
Posts: 40


why ??dont you saw the left side of message window
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Please avoid pretty coloured text; many people find it difficult to read. I have changed the previous text to black.
s.palanivel rajan
Ranch Hand

Joined: Sep 22, 2009
Posts: 40
ok cambell.. no problem i understand...
but if it is the case then why these colours are given...
Rakib Jahin
Greenhorn

Joined: Jul 14, 2009
Posts: 5
nice replies.it was helpful for me
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Thank you. A few colours might be helpful, but . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Abstract Class and Interface, Which scenarios we are using both?
 
Similar Threads
abstract class
abstract or interface - which one to choose?
abstract class Vs interface
what are the most common questions on Java job interviews?
abstract class and interface