| 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: 32627
|
|
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.
|
 |
 |
|
|
subject: Diff bw Abstract class and Interface
|
|
|