... then the method name getName
and an empty set of parentheses because no arguments are being passed. When getName
is called:
The app transfers execution from the call (line 14 in
main
) to methodgetName
’s declaration (lines 14–16 of Fig. 7.1). BecausegetName
was called via themyAccount object
,getName
“knows” which object’s instance variable to manipulate.Next, method
getName
performs its task—that is, it returns thename
(line 15 of Fig. 7.1). When the return statement executes, program execution continues wheregetName
was called (line 14 in Fig. 7.2).System.out.printf
displays theString
returned by methodgetName
, then the program continues executing at line 17 inmain
.
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.