March 2019
Intermediate to advanced
242 pages
6h 21m
English
In JDK 9 and other previous versions, you could define a variable of the base class and assign an instance of its derived class to it. The members that you could access using the variable were limited to the ones that were defined in the base class. This is no longer the case with var, since the type of the variable is inferred by using the specific type of the instance that is assigned to it.
Imagine a class Child extends a class Parent. When you create a local variable and assign it an instance of the Child class, the type of the variable is inferred as Child. This looks simple. The following is an example:
class Parent { void whistle() { System.out.println("Parent-Whistle"); } } class Child extends ...Read now
Unlock full access