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 Diff bw Abstract class and Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Diff bw Abstract class and Interface " Watch "Diff bw Abstract class and Interface " New topic
Author

Diff bw Abstract class and Interface

mani senthil
Greenhorn

Joined: Jan 18, 2007
Posts: 17
Kindly tell me the diffrence between Abstract class and Interfac.
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
A quick trip to the FAQ brings up this: http://faq.javaranch.com/view?InterfaceVsAbstractClass


"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
Urs Waefler
Ranch Hand

Joined: Mar 13, 2007
Posts: 77
Hi

There are several differences between abstract classe and interface.

I think, one main difference is, an abstract class can contain non-abstract methods. In an interface every method is abstract.

You can not instantiate an abstract class. Also an interface you can not instantiate.

If one method is abstract, the class must be abstract. But an abstract class does not have to contain any abstract method.

In a non-abstract class there is no abstract method.

In an interface every method is abstract an public.

Regards
Urs


SCJP 1.4
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
Not quite true that you can't instantiate an abstract class or an interface. You can't instantiate them directly, but you can use them, to create anonymous classes. Example. Runnable is an interface in java.lang which has one method called . . . void run().
You will see several instances in the Swing part of the Java tutorials where they start their application like this:-To instantiate an interface you have to give it a class body with (){} and implement all its methods inside the {}.
Because you implement its methods that is why you say public class Foo implements BarInterface.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diff bw Abstract class and Interface