8000 added content · JavaK2/JavaNotes@4189b82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4189b82

Browse files
author
Ram swaroop
committed
added content
1 parent 482764f commit 4189b82

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

_posts/2015-08-20-nested-classes.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,24 @@ The `doStuff(Foo f)` in `Bar` class takes an object of a class that implements `
377377
anonymous class which is an implementation of the `Foo` interface as an argument to the `doStuff()` method (in line 4).
378378
This we call it as __Argument Defined Anonymous Class__.
379379

380+
Please note that argument defined anonymous class end like `});` but normal anonymous class end like `};`.
380381

382+
## Static Nested Class
383+
384+
Static Nested Classes are sometimes referred to as static inner classes, but they really aren't inner classes at all
385+
based on the standard definition of an inner class. While an inner class (regardless of the flavor) enjoys that special
386+
relationship with the outer class (or rather, the instances of the two classes share a relationship), a static nested
387+
class does not. It is simply __a non-inner (also called "top-level") class scoped within another__.
388+
389+
So with static classes, it's really more about name-space resolution than about an implicit relationship between the
390+
two classes. A static nested class is __simply a class that's a static member of the enclosing class__:
391+
392+
{% highlight java %}
393+
class BigOuter {
394+
static class Nested { }
395+
}
396+
{% endhighlight %}
397+
398+
The class itself isn't really `static`; there's no such thing as a `static` class. The `static` modifier in this case says
399+
that the nested class is a `static` member of the outer class. That means it can be accessed, as with other `static`
400+
members, without having an instance of the outer class.

0 commit comments

Comments
 (0)
0