8000 content changes · JavaK2/JavaNotes@42743e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 42743e8

Browse files
author
Ram swaroop
committed
content changes
1 parent 04ad549 commit 42743e8

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ A regular inner class scoped inside another class's curly braces, but outside an
185185
same level that an instance variable is declared) is called a __method-local inner class__.
186186

187187
{% highlight java linenos %}
188-
class Outer {
189-
188+
class Outer {
190189
private String x = "Outer";
191190

192191
void doStuff() {
@@ -198,10 +197,8 @@ class Outer {
198197
} // close inner class method
199198
200199
} // close inner class definition
201-
202-
} // close outer class method doStuff()
203-
204-
} // close outer class
200+
}
201+
}
205202
{% endhighlight %}
206203

207204
In the above example, `class Inner` is the method-local inner class. But the inner class is useless because you are never
@@ -212,8 +209,7 @@ use the inner class, you must make an instance of it somewhere within the method
212209
The following legal code shows how to instantiate and use a method-local inner class:
213210

214211
{% highlight java linenos %}
215-
class Outer {
216-
212+
class Outer {
217213
private String x = "Outer";
218214

219215
void doStuff() {
@@ -230,10 +226,8 @@ class Outer {
230226
mi.seeOuter();
231227
232228
} // close inner class definition
233-
234-
} // close outer class method doStuff()
235-
236-
} // close outer class
229+
}
230+
}
237231
{% endhighlight %}
238232

239233
### What a Method-Local Inner Object Can and Can't Do
@@ -268,11 +262,12 @@ class MyOuter {
268262
class MyInner {
269263
public void seeOuter() {
270264
System.out.println("Outer x is " + x);
271-
System.out.println("Local var z is " + z); // won't compile, making 'z' final will solve the problem
272-
} // close inner class method
273-
} // close inner class definition
274-
} // close outer class method doStuff()
275-
} // close outer class
265+
System.out.println("Local var z is " + z); // won't compile, making 'z' final
266+
// will solve the problem
267+
}
268+
} // close method-local inner class
269+
}
270+
}
276271
{% endhighlight %}
277272

278273
* A local class declared in a `static` method has access to only `static` members of the enclosing class, since there is no

0 commit comments

Comments
 (0)
0