• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

boolean return

 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Please let me know why "true" prints instead of "false" at Line 12. hello() method in callMe() method returns false know..
 
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're calling the callMe() method. It returns true. Therefore "true" is printed.

If you think it should print "false", you have to explain why the callMe() method would return false. Why do you think it returns false?
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am expecting "false" to be printed because hello() method in callMe() method returns false..The first statement in callMe() method i.e., hello() method should return false and come out of the callMe() method before executing return true at Line 4.
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no concept of multiple level of returning values...

hello() returns "false" to callMe() method... Thats all hello() method stackframe will disappear... So next instruction to be executed will be "return true"... So, "true" will be returned and so print "true" value...
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Harikrishna Gorrepati wrote:I am expecting "false" to be printed because hello() method in callMe() method returns false..The first statement in callMe() method i.e., hello() method should return false and come out of the callMe() method before executing return true at Line 4.



The method hello() finishes its job by returning the value. How do you say that's the finishing point of the callMe() method? If so, what is the point of having the callMe() method? The hello() method simply returns a value to the caller method, but, you don't use that returned value in you caller method. That's all.
 
Ranch Hand
Posts: 251
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes abimaran is right.
 
Thakur Sachin Singh
Ranch Hand
Posts: 251
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you want to false value then one statement is reduced from the callme() method.
 
Thakur Sachin Singh
Ranch Hand
Posts: 251
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if hello() method called directly with return keyword then return value of hello() method is not lost.
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic