|
What do you suspect will happen with the following method call? pointB.move( 14.305, 34.9-12.6 ); A good answer might be:This is an error, because the parameter list has two floating point values, not the two int values required. | |
Parameters Must be the Correct TypeWhen a method starts running, it must have the right number of parameters, and each parameter must be of the required type. However, sometimes, just before a method starts running, the values supplied in a parameter list are converted to the required type. There are two ways in which this can happen:
The(requiredType)(expression) (requiredType) is something like (int).
The (expression) is an ordinary expression.
If it is a single variable, you don't need the surrounding parentheses.
Here is an example program that shows a type cast:
In this case, a type cast is required for both parameters because converting a floating-point number to an int will usually lose information. In casting a floating-point value to an int, the fractional part will be lost. (Not rounded.) | |
QUESTION 5:What will be the output of the program? Click Here after you have answered the question |