Skip to content

Commit a4c494f

Browse files
author
Ram swaroop
committed
added content
1 parent d131ad5 commit a4c494f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ class Popcorn {
294294
class Food {
295295
Popcorn p = new Popcorn() {
296296
public void pop() {
297-
System.out.println("anonymous popcorn");
297+
System.out.println("this method overrides pop() in Popcorn class");
298+
}
299+
public void push() {
300+
System.out.println("new method in anonymous inner class");
298301
}
299302
};
300303
}
@@ -306,7 +309,9 @@ of an anonymous (unnamed) subclass of `Popcorn`.
306309
__Polymorphism comes to play in Anonymous Inner Class__ as in the above example, we're using a superclass reference
307310
variable type to refer to a subclass object. So, we need to keep in mind some points:
308311

309-
312+
* You can only call methods on an anonymous inner class reference that are defined in the reference variable type. So,
313+
in the above code, you cannot call `p.push()` as `p` is a reference variable of type `Popcorn` and `Popcorn` class does
314+
not have any method named `push()`.
310315

311316
312317

0 commit comments

Comments
 (0)