Skip to content

Commit 482764f

Browse files
author
Ram swaroop
committed
added content
1 parent 21351e7 commit 482764f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,32 @@ interfaces implemented by the superclass.
349349

350350
### Argument Defined Anonymous Inner Class
351351

352+
Consider the below code:
352353

354+
{% highlight java linenos %}
355+
class MyWonderfulClass {
356+
void go() {
357+
Bar b = new Bar();
358+
b.doStuff(new Foo() {
359+
public void foof() {
360+
System.out.println("foofy");
361+
} // end foof method
362+
}); // end inner class def, arg, and b.doStuff stmt.
363+
} // end go()
364+
}
353365

366+
interface Foo {
367+
void foof();
368+
}
354369

370+
class Bar {
371+
void doStuff(Foo f) {
372+
}
373+
}
374+
{% endhighlight %}
355375

376+
The `doStuff(Foo f)` in `Bar` class takes an object of a class that implements `Foo` interface. So, we just passed an
377+
anonymous class which is an implementation of the `Foo` interface as an argument to the `doStuff()` method (in line 4).
378+
This we call it as __Argument Defined Anonymous Class__.
356379

357-
358380

0 commit comments

Comments
 (0)