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 Only one question in interface and abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Only one question in interface and abstract class" Watch "Only one question in interface and abstract class" New topic
Author

Only one question in interface and abstract class

Shanmugam nagaraj
Ranch Hand

Joined: May 07, 2007
Posts: 76
Hi,
my question is regarding Interface and abstract class.

I know the difference between the abstract class and interface.
But I need to know in real time application when we use the interface and when we use the abstract class.

What all are the scenario we use this both can any one help me out regarding this pls..

Thanks


Shanmugam N


Thanks <br />Shanmugam N
Ricky Clarkson
Ranch Hand

Joined: Jul 27, 2006
Posts: 131
An interface is useful for declaring capabilities. An abstract class is useful for inheriting them. Use an abstract class when you need to inherit behaviour (or when inheriting behaviour is the best way of reusing code).

You never need to inherit behaviour, you can always get it in some other way (composition, just calling a static method, etc.), and those other ways are, in my opinion, always better than subclassing. Therefore, never use an abstract class, if you ever work with me.
Anita Singh
Greenhorn

Joined: May 18, 2007
Posts: 17
ointerface contains methods that must be abstract; abstract class may contain concrete methods.
ointerface contains variables that must be static and final; abstract class may contain non-final and final variables.
omembers in an interface are public by default, abstract class may contain non-public members.
interface is used to "implements"; whereas abstract class is used to "extends".
interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.
interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces.
interface is absolutely abstract; abstract class can be invoked if a main() exists.
interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.
If given a choice, use interface instead of abstract class.

Anita Singh


SCJP 5.0 100%
Anita Singh
Greenhorn

Joined: May 18, 2007
Posts: 17
ointerface contains methods that must be abstract; abstract class may contain concrete methods.
ointerface contains variables that must be static and final; abstract class may contain non-final and final variables.
omembers in an interface are public by default, abstract class may contain non-public members.
interface is used to "implements"; whereas abstract class is used to "extends".
interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.
interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces.
interface is absolutely abstract; abstract class can be invoked if a main() exists.
interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.
If given a choice, use interface instead of abstract class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Only one question in interface and abstract class