 Let's look at geometric object in its subclasses again. In addition to get area and get perimeter, which are overridden in each of the subclasses, I've added to each subclass a method that is unique to that subclass. Here in circle, I've added a getDiameter method that returns the circle's diameter. That's sort of a useless method, but I needed something. Here in rectangle, I've added a getDiagonal method that returns the length of the diagonal of the rectangle. And here in triangle is a method that returns the opposite angles for all three sides as an array. Let's take a look at this test program. We already know that this is valid. I can set a geometric object variable to refer to a rectangle object, because any rectangle is a geometric object. Because this is, at heart, a rectangle, what I'd like to do is show what its diagonal is. If I try something like this, double-diag equals shape.getDiagonal, and then print the result, this will not compile properly. Because as far as the compiler is concerned, shape is a geometric object, and geometric objects don't have a getDiagonal method. To get around this problem, I can use a cast. I can say shape is really a rectangle. I'm telling the compiler to treat shape as a rectangle, and rectangles do have a getDiagonal method. Now, when I compile, it's successful, and when I run it, I get the correct result. By the way, the outer parentheses in the cast are necessary to make the compile work correctly. Now let's look at this code. We have an array of geometric objects, and a loop that prints out what each one is, and its area and perimeter. This works fine because all the subclasses have overridden to string, get area, and get perimeter. It compiles fine, and it runs fine. What I'd like to do now is get the specific information for each shape. For the circles, I want to print their diameter, for the rectangles, their diagonal, and for the triangle, the angles. Unlike the preceding example, where I knew I had a rectangle, I don't want to write this program to depend on knowing in advance what kind of a geometric object each array entry will be. Here's the pseudocode for what I want to do. If the shape I'm looking at is a circle, then it's okay to cast it to a circle and call its getDiameter method and print that. This part I already know how to do. I can say diameter equals, do my cast to a circle, and then getDiameter. This will compile okay because I'm telling the compiler, treatShape subi as a circle, and circles do have a getDiameter method. And now I can print it out. The question now is, how do I determine whether an object is a circle object, a rectangle, or a triangle at runtime? The answer is the instance of operator. If shape subi is an instance of the circle class, this expression will return true, and it means I have a circle. If shape subi is a triangle or a rectangle, it's not an instance of the circle class, and the expression will return false. Similarly here, I can ask, if shape subi is an instance of rectangle, then it's okay for me to say diagonal is treatShape subi as though it were a rectangle with a cast, and then it's okay to have the getDiameter method call, and I can print out the length of the diagonal to save some time. I can use the code to handle triangles. Let's compile, and let's run. And there we have each of the shapes with its area perimeter and its specific information, the diameter, the diagonal, and the angles. The takeaway from this video is to remember how polymorphism works. At compile time, whatever class you used to declare the variable is the one the compiler sees. If you want to use a method that belongs to a subclass, you must explicitly cast the variable to that subclass. But before you cast, you need to make sure that the object really is a member of that class, and you use the instance of operator to give you that information at runtime.