What I know about interfaces is that:
1) Interfaces are list of methods i.e Template
2) Interface type can refer to an object of class which implements that interface.
Today I came across below code
interface Test
{
void greet();
}
public class Demo
{
public static void main(String[] args)
{
Test t = new Test() ---> Is it correct ? WHY ?
{
public void greet()
{
System.out.print("\nHi, Best wishes to way2java.com\n");
}
};
t.greet();
}
}
Am not able understand the intention of below code snippet
Test t = new Test()
1) Do Interfaces have constructors ? My knowledge says Interfaces are having only methods lists but not a definition
2) Is it legal to create a object of Interface ? My knowledge says, the interface type can only refer to an object of class which implements that interface.
3) If its legal then whats the purpose ?
Thanks