Skip to content

Commit 6375dac

Browse files
author
Ram swaroop
committed
inner class instantiation examples added
1 parent 3719d85 commit 6375dac

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ To create an instance of an inner class, you must have an instance of the outer
7878
are no exceptions to this rule: __An inner class instance can never stand alone without a direct relationship to an
7979
instance of the outer class__.
8080

81+
#### Instantiating an Inner Class from Within the Outer Class
82+
8183
{% highlight java linenos %}
8284
public class MyOuter {
8385
private int x = 7;
@@ -95,6 +97,15 @@ public class MyOuter {
9597
}
9698
{% endhighlight %}
9799

100+
#### Instantiating an Inner Class from Outside the Outer Class Instance Code
101+
102+
{% highlight java %}
103+
public static void main(String[] args) {
104+
MyOuter mo = new MyOuter(); // gotta get an instance!
105+
MyOuter.MyInner inner = mo.new MyInner();
106+
inner.seeOuter();
107+
}
108+
{% endhighlight %}
98109

99110

100111

0 commit comments

Comments
 (0)