138k views
5 votes
Which of the following variable declarations is a correct assignment?

A. int x = 97.2;
B. char c = 65.5;
C. String w = 82.4;
D. double y = 82;
E. String i = 82;

1 Answer

6 votes

Answer:

Option D: double y = 82;

Step-by-step explanation:

In Java programming, it is acceptable to assign an integer (lower type) to a double type (higher type) variable. By assigning an integer to double type variable using the "=" operator, the integer will be converted to double type implicitly. It is known as the implicit type casting.

For example, double y = 82 will convert integer 82 (integer) to 82.0 (double).

User Gonzalo Larralde
by
5.2k points