How to differentiate static types from dynamic types?

Asked

Viewed 121 times

0

all right with you guys?

I had another OOP class today, and today’s topic was the beginning of substitution and the static and dynamic types.

I did not understand the definition of these concepts and their usefulness... Could someone explain this to me with some simple example of understanding?

I thank you in advance for your help.

  • More can be seen in https://answall.com/search?tab=votes&q=typing%20din%C3%a2mica%20e%20est%C3%a1tica

1 answer

1

All right, let’s go.

Static types are defined at the time the code is written and checked at compile time, and do not allow values that do not fit the defined type to be assigned. For example, a type variable int you can only receive int (or short values, considering Java) or integer values of other types and you need to use casting. Static type are common in compiled languages.

Dynamic types accept any value for their assignment. Using the example of a dynamically typed language (javascript), one can define a variable and assign a numerical value to it, and a few lines later change the value to a string type. Dynamic types are common in interpreted languages (Javascript, Python, etc).

One more example: the expression int a = "1" results in a compilation error in a statically typed language (C++, Java, etc).

But the expressions var a = "1"; a = 5; a = { name: "asdf"}; are normally interpreted and executed in a dynamically typed language (Javascript).

  • Do these concepts apply to class hierarchy? If so, how?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.