Interface in Class

Interface in Class


In the Nested interfaces series, here, Interface in Class is discussed.

Note: It is advised to read the basics and types of inner classes before proceeding further.

Interface in Class is a tieing mechanism between an interface and a class. The programmers using the interface can make use of the functionality (methods) of the enclosing class provides. It is another style of organizing the code.

"Interface in Class" is also useful to associate a class functionality with an interface.

See this code for easy understanding.

The programmer implementing the interface Building can construct the pillars and ceiling with the Ultratech cement, the functionality provided by the class Structure.

Now let us go for some programs.

Note: Nested interfaces are implicitly static. That is, nested interfaces can be implemented without the help (using) of outer interface.

Let us go a little bit deep. Observe the following code.

Without extending Outer1, the Test object t1 can not call show() method.

Leave a Reply

Your email address will not be published. Required fields are marked *