Salesforce Platform Developer I (legacy) — Question 94
Which is a valid Apex assignment?
Answer options
- A. Integer x=5*1.0;
- B. Integer x =5.0;
- C. Double x =5;
- D. Float x =5.0;
Correct answer: C
Explanation
Option C is correct because it assigns an integer value to a Double variable, which is valid in Apex. Options A and B are incorrect as they attempt to assign a floating-point number to an Integer type, which is not allowed. Option D is also incorrect since it assigns a floating-point value to a Float type, but Float is less commonly used in Apex compared to Double.