wood burning stoves 2.0
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

Diff bw Abstract class and Interface

mani senthil

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

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.


SCJP 1.4
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46410
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
It's not a secret anymore!