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

Skip to content

Commit 39b26f6

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

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,12 @@ In the above code, the `Popcorn` reference variable __DOES NOT__ refer to an ins
307307
of an anonymous (unnamed) subclass of `Popcorn`.
308308

309309
__Polymorphism comes to play in Anonymous Inner Class__ as in the above example, we're using a superclass reference
310-
variable type to refer to a subclass object. So, we need to keep in mind some points:
311-
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()`.
310+
variable type to refer to a subclass object. And when you call `p.pop()` then the `pop()` inside `Food` class will be
311+
called instead of the one in `Popcorn` class.
312+
313+
But we need to keep one thing in mind, i.e, you can only call methods on an anonymous inner class reference that are
314+
defined in the reference variable type. So, in the above code, you cannot call `p.push()` as `p` is a reference variable
315+
of type `Popcorn` and `Popcorn` class does not have any method named `push()`.
315316

316317
317318

0 commit comments

Comments
 (0)
0