File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -294,7 +294,10 @@ class Popcorn {
294294class 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
307310variable 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
You can’t perform that action at this time.
0 commit comments