• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

when does return statement execute ?  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code has been adapted from OCA/OCP test prep java 8



output:
Music!Music!2  
When I had invoked the playMusic() method, it just printed Music!, then when I use println method, then Music!2 was printed. my question is : when I invoked the playMusic() method, why didn't it print Music!2 ?
Thanks
 
Saloon Keeper
Posts: 9857
199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you didn't tell the main() method to print the result of the first time you call the playMusic() method. It returned 2, but you just ignored the return value. The second time you call playMusic(), you do it inside a println() call.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!