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.
- Posted by: Sabyasachi Chowdhury
- Posted on: June 30 2004 09:28 EDT
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.
- Abstract methods in an Interface by Sohail Sikora on June 30 2004 11:06 EDT
- Abstract methods in an Interface by Stefan Zobel on June 30 2004 13:24 EDT
- Abstract methods in an Interface by Abhijeet Mahalkar on September 27 2005 04:09 EDT
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).
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.