My code is as following, my question is that what is the meaning of line 1, if there is not meaning then why does eclipse allows infact gives inner as available option on typing ClassO.
It would have been meaningful if the inner was a static nested class instead of inner interface and if it meaningful as it is then what is the use, what all can i do with it ?
public class InterfaceInsideClass
{
public static void main(String[] args)
{
ClassO.inner **// Line 1**
}
}
class ClassO
{
interface inner
{
void msg();
}
class Two implements inner
{
public void msg()
{
System.out.println("Class Two");
}
}
class Three
{
public void msg()
{
System.out.println("Class Three not implementing interface but having same method");
}
}
static class Four
{
public void msg()
{
System.out.println("Class Four");
}
}
}
One on the most common use of static nested classes and nested interface is for another layer of packaging.
If the particular interface is only intended to be implemented within a particular class or its subclasses via by its inner or nested classes then it makes sense to include that interface inside those classes.
Good example is: java.util.Map.Entry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With