posted 21 years ago
Hi Swati,
Before going into abstract class and interface we will see what is an abstract method which is the basis of both. An abstract method is the one which is common to both. An abstract method is a method that is just declared but not implemented.
An abstract class is the one which contains atleast one abstract method and one implemented method ( normal method ) whereas an interface has all of functions abstract.
Some other minor differences :
1. All the member functions and variables are explicitly public in an Interface. Because there is no point having a private function because you cannot override it.
2. In an abstract class the methods has to be declared abstract it is not the case in an interface.
3. A subclass has to use implements to inherit an interface.
whereas an abstract class should use extend.
4. You can implement as many interfaces. you cannot do with classes.
Whether it is an interface or abstract class, all the subclasses which inherits from the class should implement those abstract method or else the class becomes abstract or interface based on atleast one of the method is implemented.
To create an object, the class has to be non-abstract, so if a
implements an interface or extends a abstract class to create an object of that type the subclass have to implement all the abstract functions.
e-mail me if u have further doubts on this.
------------------