Can We Use Variable and methods of Interface without using Keyword 'Implements'.
Note:Interface and Classes are in same Package.
Thanks in Advance..!!!
public static final
by default, so you can directly use themYou can implement an interface by means of anonymous class (without using implements
keyword)
public static void main(String[] args) throws Exception{
System.out.println(I.s); // accessing Interface I's variable
I i = new I() {
@Override
public int getS() {
return 10;
}
};
System.out.println(i.getS()); // accessing I's method
}
interface I {
String s = "test";
int getS();
}