Line 7 invokes method square
with the argument 7
. Literal integer values are treated as type int
, so the method call in line 7 invokes the version of square
at lines 12–16 that specifies an int
parameter. Similarly, line 8 invokes method square
with the argument 7.5
. Literal floating-point values are treated as type double
, so the method call in line 8 invokes the version of square
at lines 19–23 that specifies a double
parameter. Each method first outputs a line of text to prove that the proper method was called in each case. The values in lines 8 and 20 are displayed with the format specifier %f
format specifier, which is used to output values of type ...
Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.