Well some of eminent counsellors force me to accept that Interfaces cannot have variables....
no ...never ....Not At All:(
But when i encounter to this tutorial(*In support of my belief as i know already*)
[http://java.sun.com/docs/books/tutorial/java/IandI/interfaceDef.html]
Interfaces can have variables but they must be static and final OR they should be constants (statically declared).
just to test myself i am running this code where an int variable is declared inside an interface...it works fine...
why?
Here I am not declaring any method inside interface also i am not implementing that interface still it gives output?
interface A
{
int b=7;
}
public class TestInterface
{
public static void main(String args[])
{
System.out.println("value "+ A.b);
}
}
So either the tutorial is false or the java compiler do not know about the Interfaces (MayB interfaces are treated as classes internally because a .class file is created for each Interface)
OR this bug (If this is a BUG) is not fixes even in jdk1.5_16 (which i used)
OR my approach is wrong completely.
please Help me.
Thanks.