Java Patterns and instanceof
Consider the following:
We can check to see if an element of ArrayList animList is of type Dog by using instanceof.
In using patterns, the code a instanceof Dog dog checks to see if a is a Dog and then declares and creates dog as a Dog object and assigns it to a.