rajapratap, In an interface, all the methods should be (implicitly) abstract methods. In an abstract class, you can have implemented methods also. Apart from them, you can have abstract methods. You would wonder (if you haven't realised before), you can have an abstract class without any abstract methods!! These are the major differences. The minor differences being, In an interface, all the variables declared are implicitly static and final, but not so in an abstract class. In an interface, all the methods are public, but not so in an abstract class. Hope this helps, Regards, Suresh.
Hi Rajapratap, Here are some of the attributes of an interface: 1. Interface is basically a collection of abstract method definations and constants - no instance variables and no methods implementations. All the variables must be public, static, final. 2. Interface provide much of the functionality of multiple inheritence. 3. Interface is a skeleton of a class. The class while implementing an inetface must define and implement those methods. 4. Declarations are always public even if they are not mentioned. Attributes of abtract class: A class that is declared abstract that may not be instantiated. A class must be declared abstract under the following condition: 1> Contain one or more abstract methods. 2> inherits abstract method for which it does not provide implementation. 3> implements an interface but does not provide implementation for every method. Regards, Milind
Originally posted by rajapratap: Can anyone tell me the exact difference between interface and abstract class?
To be little precise with.. Interface are the most beautiful and powerful component provided by Sun people. To get the utility of an Abstract class one has to extend it.. and that forms a heirarchy. Usually the utility of an abstract class persist with one heirarachy... (or we can abstract out the common functionality of a perticular heirarachy and put it in abstract class). Where in case with Interface.. it has nothing to do with any class heirarachy.. things which you find common amongst all heirarchy can be put in interface. Thats the greatest thing I belive. !!! - Keyur