I know that all methods inside the interface are abstract and meant to be overriden (even though we did not explicitly declare those methods public abstract, it is automactically declared for us). Is this mean:
1. Methods inside interface have to be kept public all the time? 2. Can we declare type of the method others besides void? 3. Can we have paramateres on the methods? 4. Can we have a static methods in interface?
Examples which of these are valid declarations in a interface definition: 1. void methoda (); 2. public double mothoda (); 3. public final double mothoda(); 4. static void methoda (double d1); 5. protected void methoda (double d1);
Joined: Apr 19, 2006
Because of my impatience, I have tried running all the scenarios. The result are:
1. Yes, methods have to be kept public inside interface. 2. Yes 3. Yes 4. If we try to decare a static method, we will get a response "modifier static not allowed here"
So, I assume for the 4 examples case no 1&2 are valid ones. One more point, final method is not allowed in interface because final means can not be overriden, as we know the purpose of having abstract methods are to be overriden by classes which implement the interface.