Diagnostic Quiz
Problems
Q8. Statically, Dymically, Strongly or Weakly Typed Language

Java is:
Statically typed
This means the variable can only hold values of the declared type.
Strongly typed
This means everything needs to make sense, a.k.a if there are any problems with the program, it is not due to the type. For example, no implicit narrowing conversion is allowed
This code snippet will generate a compilation error.
Q15. Widening/Narrowing type conversion
Java allows a variable of type to hold a value from a variable of type only if . This step is called widening type conversion.
The term "widening" is easy to see for primitive types — the subtype has a narrower range of values than the supertype. The opposite conversion is called narrowing because the size is narrower.

In this problem i is int and f is float, and int <: float, so f = i is a widening type conversion. For this question, we can get two tips as follows:
Java is a strongly typed language, but it allows widening type conversion and will do this automatically without explicit casting.
However, narrowing type conversion without explicit casting is not allowed in Java and it will generate a compile-time error (so, there is even no chance to get an run-time error here)
Tips
Java is a strongly typed language, but it allows widening type conversion and will do this automatically without explicit casting.
However, narrowing type conversion without explicit casting is not allowed in Java.
Last updated