File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Use for nested interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Use for nested interfaces" Watch "Use for nested interfaces" New topic

Use for nested interfaces

Bill Nelsen

Joined: Aug 11, 2004
Posts: 27
I started to play around with nested interfaces, because I read that by definition they are static. So this is the trivial example that I arrived at,

interface A {
interface B {
void help();
class Base implements A.B {
public void help() { System.out.println("Help"); }

class Test {
static public void main(String[] args) {
A.B b = new Base();;

Since the nested interface is static, it requires this unusual notation (or at least I think that it does). I have a difficult time intuitively picturing what a static interface would look like. Is there a good use for a nested interface or is it just a feature (like interfaces that contain concrete classes), which is just there for completeness, but doesn't really serve a useful purpose??
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Nested interfaces also means interfaces defined within a class. In this article an example of such nested interfaces is given.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Bill Nelsen

Joined: Aug 11, 2004
Posts: 27
Thanks for the link to a great article. I am reading all 3 parts of the article.
I agree. Here's the link:
subject: Use for nested interfaces
jQuery in Action, 3rd edition