zuai-logo

Polymorphism

Emily Wilson

Emily Wilson

4 min read

Listen to this study note

Study Guide Overview

This guide covers static and dynamic types of objects, focusing on how they are determined during object creation. It then explains method calling and polymorphism, illustrating how static and dynamic types influence which method is executed. The guide uses code examples to demonstrate the interaction between static/dynamic types and static/non-static methods.

Static and Dynamic Types

Now that we have established a little bit about polymorphism in the last topic, let's talk some more about it. Every object has a static type and a dynamic type. Let's use the hierarchy tree from the last topic:

markdown-image

Courtesy of Wikimedia Commons.png&psig=AOvVaw2elTUnxk5JGLw1X7_9WGgv&ust=1598242386382000&source=images&cd=vfe&ved=0CAMQjB1qFwoTCMDX8fG9sOsCFQA...

Question 1 of 5

Given the declaration Animal cat = new Cat();, which type is the static type of the cat object? 🤔

Cat

Object

Animal

None of the above