Samples JDK
A.java
1 package com.freemindcafe.oops.innerclass.mypackage;
2 
5 
6 
7 public class A {
8 
9  public static void main(String[] args) {
10  MessageProcessor messageProcessor = new MessageProcessor();
11 
12  //Every classes objects can be passed
13  //and can be used in other packages outside of this package.
14  //These access qualifiers are applicable only at compile time.
15 
16  messageProcessor.process(new B());
17  messageProcessor.process(new A().new C());
18  messageProcessor.process(new D());
19  }
20 
21  //nested static private class
22  private static class B implements IMessageProvider{
23 
24  @Override
25  public String provideMessage() {
26  return "in B";
27  }
28 
29  }
30 
31  //inner class (nested public class)
32  public class C implements IMessageProvider{
33 
34  @Override
35  public String provideMessage() {
36  return "in C";
37  }
38 
39  }
40 
41  //nested static public class
42  public static class D implements IMessageProvider{
43 
44  @Override
45  public String provideMessage() {
46  return "in D";
47  }
48 
49  }
50 
51 }