Abstract methods in an Interface

Discussions

General J2EE: Abstract methods in an Interface

  1. Abstract methods in an Interface (4 messages)

    I know that in an Abstract class u can have one or many abstract method rather if in a class there are any abstract method than the class also becomes abstract.

    But I have seen abstract methods in and Interface many time.Can any one tell me the significance of having abstract methods in an Interface.

    Regards
    Sabyasachi Chowdhury
  2. http://mindprod.com/jgloss/interfacevsabstract.html
  3. Can any one tell me the significance of having abstract methods in an Interface.
    If I understand you correctly, you mean something like the following:

    public interface MyInterface
    {
        public abstract int myMethod1(int i);
        int myMethod2(int i);
    }

    Interface methods are by definition public and abstract, so "public" and "abstract" are simply two optional keywords, the compiler allows you to leave off. There is no difference between myMethod1 and myMethod2 with respect to the generated bytecode, so myMethod2 is also "public abstract" (e.g. some decompilers always add "public abstract" when decompiling interfaces).

    HTH,
    Stefan
  4. Thanks Stefan
  5. Just to add to your knowledge.

    Do you know you can have a inner class into an interface? This class can be a concreate class, static class, private or protected/ public class.

    in this inner class you can define a concreate method or final / abstract method as well.

    regards

    abhijeet mahalkar