Skip to content

Commit aa981a7

Browse files
author
Ram swaroop
committed
added content
1 parent ab71b0d commit aa981a7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,29 @@ class BigOuter {
398398
The class itself isn't really "`static`", there's no such thing as a `static` class. The `static` modifier in this case says
399399
that the nested class is a `static` member of the outer class. That means it can be accessed, as with other `static`
400400
members, without having an instance of the outer class.
401+
402+
{% highlight java linenos %}
403+
class Outer {
404+
static class Nest {
405+
void go() {
406+
System.out.println("hi outer");
407+
}
408+
}
409+
}
410+
411+
class Inner {
412+
static class Nest {
413+
void go() {
414+
System.out.println("hi inner");
415+
}
416+
}
417+
418+
public static void main(String[] args) {
419+
Outer.Nest outerNest = new Outer.Nest(); // access static inner class
420+
outerNest.go(); // present inside a different class
421+
422+
Nest innerNest = new Nest(); // access static inner class
423+
innerNest.go(); // present inside the same class
424+
}
425+
}
426+
{% endhighlight %}

0 commit comments

Comments
 (0)