The dynamic type refers to the actual type of an object at runtime. It may differ from its static (declared) type and is determined based on the specific instance assigned to it during program execution.
Think of the dynamic type as a disguise that an object wears. Just like how someone can put on different disguises to appear as different characters, an object's dynamic type can change during runtime, allowing it to behave differently based on its current form.
Static Type: The static type refers to the declared type of a variable or expression at compile-time.
Type Inference: Type inference is a feature in some programming languages where the compiler automatically determines the data type of a variable based on its assigned value.
Late Binding: Late binding is a mechanism where the specific implementation of a method is determined at runtime rather than compile-time.
Assume the following code is valid. What is the static type and dynamic type of the variable "ref"? ``` G ref = new H(); ```
Assume the following code is valid. What is the static type and dynamic type of the variable "jack"? ``` Person jack = new Student(); ```
Suppose there is a Car class that extends the Vehicle class and whose constructor takes in the “brand” and “year” parameters. What is the static type and dynamic type of the variable "lambo" in the following code? ``` Car lambo = new Car(“Lamborghini”, 2005); ```
Study guides for the entire semester
200k practice questions
Glossary of 50k key terms - memorize important vocab
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.