A cast is required in which of the following situations? a. using charAt to take an element of a String and store it in a char b. storing an int in a float c. storing a float in a double d. storing a float in an int e. all of the above require casts

Respuesta :

Answer:

Option(d) i.e "storing a float in an int" is the correct answer for the given question.

Explanation:

  • Typecast is used for the changing the one datatype to the another datatype Their are two types of casting  

1 implicit

In this typecast we change the smaller datatype into the larger datatype.

For example

int to float  

2 Explicit  

In this typecast we change the larger datatype into the smaller datatype in an explicit manner.

For example

float to int.

  • in the given question we required the casting in the option(d) i.e "storing float in an int" That's why this option is correct and all other options are incorrect.

Otras preguntas