This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 37950
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Diff bw Abstract class and Interface
 
Similar Threads
HttpServlet class
ABSTRACT
A question about container!
usage of a class
A mock question