Thursday, March 12, 2009

Can an interface have variables defined in it? How do you use

Question :Can an interface have variables defined in it? How do you use
them? (CoreJava)

Answer :Yes we can have variables defined in an Interface. Have a look at the
class below to
know how to use those variables
public interface MyInterface
{
String STR1 = "STR1";
String STR2 = "STR2";
}
public class MyTestClass implements MyInterface
{
public static void main(String args[])
{
System.out.println(STR1);
}
}

No comments: