Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Return Statements

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, "It's been a long time since I rock and rolled", as the song goes. So after a lengthy hiatus, i'm back. Full of cobwebs.

I got as far as completeing and having marked, the 4th (or 5th?) Java assignment.

So i'm trying to pick up where i left off.

Anyway, i've a problem folks, it concerns (I think) the use of the "Return" word.

Below is a short program i've copied out of a book:-



What I don't understand is, in the main class, I call the method "setDim", like so.....

mybox1.setDim(10, 20, 15);

And this method takes 3 parameters, right?

Well, after that, the method "volume" is called on. OK.

From that point on, how do we then manage to arrive back in the main class

Any help would be greatly appreciated. Cheers in advance
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai steve,
actually i am not getting what r u talking abt. This statement
---------------
stmt1: vol = mybox2.volume();
stmt:2 System.out.println("Volume is " + vol);
} // end of main
----------------------------
gets executed in the main itself. the control will be transfered automatically from the method 'volume()' in Class Box to the stmt1 and is assigned to vol and next the println stmt gets executed and hence it reaches the end of main method, it terminates.and if u write any code like another call to volume method after stmt2 then that will execute and gets terminated.
hope this clears ur doubt.if not feel free to ask me.
cheers & regds,
Mahesh
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are asking how a method knows where to return to.

Basically, the process of calling a method includes saving the return address in a work area called a "stack frame". Any return statement will retrieve the return address from the stack frame and go there.

There is a lot more to the call/return process, but this is what you asked.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic