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

Skip to content

Commit b1a6d1f

Browse files
author
Ram swaroop
committed
added content
1 parent 674d5c3 commit b1a6d1f

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,30 @@ associated instance of the enclosing class. If you're in a `static` method, ther
277277
## Anonymous Inner Classes
278278

279279
Inner class declared without any class name at all is known as __Anonymous Inner Class__. These can be seen as two types:
280-
1. Plain/Normal Anonymous Inner Class
281-
2. Argument defined Anonymous Inner Class
280+
1. Plain/Normal Anonymous Inner Class
281+
2. Argument defined Anonymous Inner Class
282282

283283
1. Plain/Normal Anonymous Inner Class also comes in two flavors:
284284

285-
i. Flavor 1:
285+
a. Flavor 1:
286+
287+
{% highlight java linenos %}
288+
class Popcorn {
289+
public void pop() {
290+
System.out.println("popcorn");
291+
}
292+
}
293+
class Food {
294+
Popcorn p = new Popcorn() {
295+
public void pop() {
296+
System.out.println("anonymous popcorn");
297+
}
298+
};
299+
}
300+
{% endhighlight %}
301+
302+
In the above code, the Popcorn reference variable __DOES NOT__ refer to an instance of Popcorn, but to an instance of an
303+
anonymous (unnamed) subclass of Popcorn.
286304

287305
288306

0 commit comments

Comments
 (0)
0