The Wikipedia article on the subject of inner classes enumerates a number of programming languages that support nested class definitions. Historically speaking, which programming language first added nested classes to its feature set?
The first language with nested classes was Beta, a successor to Simula. They are carried even further in Beta's successor, gBeta. A modern language that carries them quite far is Newspeak. Scala's nesting also works very similar to Beta's.
Java's inner classes are inspired by Beta's but (at least according to some people who know Beta quite well and were also involved in the design of Java) they don't fully capture all the features. (I am quoting quite liberally here, I think the actual quote was something more like "the people who designed Java tried copying nested classes without understanding them".)
Note that in your question, you use the term "nested class definitions", which is ambiguous: It can mean "nested definitions of classes" or it can mean "definitions of nested classes". In my answer, I am assuming you mean the latter, since you explicitly call out Java's inner classes, which are definitions of nested classes (with some caveats).
There are lots of languages that allow you to nest a class definition inside another class definition, but only in very few of those languages does this actually produce a nested class. For example, in Ruby:
class Foo class Bar; end end
does not produce a nested class. There is no relationship between the two classes and/or between the class
Bar and instances of class
Foo. The only thing this does is bind class
Bar to a constant named
Bar namespaced inside
Foo. The Wikipedia article is simply wrong in including Ruby in the list. At the top, the article defines meaning #1 above, but the list is actually languages supporting meaning #2.
A proper nested class has the following properties:
- The inner class is a property of instances of the outer class, i.e. the "nested" class is not actually nested inside the outer class, it is nested inside instances of the outer class, which also means that each instance of the outer class gets its own copy of the inner class (at least semantically). This means that
bare instances of
Outer) are not the same class! (And the class
- Likewise, instances of the inner class are nested inside their corresponding instances of the outer class, they are visible only to that single object (unless exported, i.e. returned from a public method).
As Konrad Rudolph pointed out in his comment, being able to lexically nest class definitions is a simple and obvious thing that is not interesting in any way.