Classes Defined within Other Constructs

suggest change

Defined within Another Class

C++

Nested Class[ref] (needs a reference to enclosing class)

class Outer {
   class Inner {
      public:
         Inner(Outer* o) :outer(o) {}

      private:
         Outer*  outer;
   };
};

Java

[non-static] Nested Class (aka Inner Class or Member Class)

class OuterClass {
    ...
    class InnerClass {
        ...
    }
}

Statically Defined within Another Class

C++

Static Nested Class

class Outer {
   class Inner {
      ...
   };
};

Java

Static Nested Class (aka Static Member Class)[ref]

class OuterClass {
    ...
    static class StaticNestedClass {
        ...
    }
}

Defined within a Method

(e.g. event handling)

C++

Local Class[ref]

void fun() {
   class Test {
      /* members of Test class */
   };
}

Java

Local Class[ref]

class Test {
    void f() {
        new Thread(new Runnable() {
            public void run() {
                doSomethingBackgroundish();
            }
        }).start();
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents