Casting Precedence
We can try to cast and call a method in a single line, but we have to be careful.
This code will not compile due to the precedence of the dot . and cast () operators.
Person person = new Employee("First", "Last", 22, "Developer", 45000.00);
String title = (Employee) person.getTitle(); // COMPILER ERROR
. is evaluated before the cast to Employee, so the compiler tries to execute getTitle() on the Person reference.
* Person does not have a getTitle() method; this is why we're trying to cast in the first place.

Even if we call a method that Person has, the cast still fails.
String info = (Employee) person.getInfo(); // COMPILER ERROR
(Employee) cast would apply to the String returned from getInfo(), but this is illegal since Employee and String are not in the same hierarchy.
We solve this by using parentheses around the reference and cast operation.
Person person = new Employee("First", "Last", 22, "Developer", 45000.00);
String title = ((Employee) person).getTitle();

Drill¶
(If you did not finish
VehicleApp, copy...solutions.vehicles.VehicleApp2)
Polymorphism/com.example.polymorphism.labs.vehicles.VehicleApp* Changerunto first print out the make and model if the vehicle is-aAutomobile, and the length in feet if the vehicle is-aBoat. * Then print the purchase price and registration fee.(Solution: VehicleApp3.java)