Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-03-2007, 09:53 AM
Member
 
Join Date: Aug 2007
Posts: 2
asterik123 is on a distinguished road
how to have function variables remember their values between calls
Hi Everyone,
I understand that we cannot declare static varibles in function definitions in java unlike in c++ that can retain their values between function calls. How can we do this in java, if the function should not accept parameters and should not reference the non-local variables.(this is a question for our assignment). Is there a way around it?can we declare static variables in c# lik in c++?

thanks in advance.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-03-2007, 11:43 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
if the function should not accept parameters and should not reference the non-local variables
You are at a dead end with these two unless you want to use class variables, ie, variables with the static modifier. But these too are not local variables.
The usual way that we preserve state is to use member variables.
Code:
class Pseudo { // Member variables with class scope. int x = 25; int y = 40; // Class variables. static int z = 99; static int v = 2; public void modifyVariables() { x += 25; y += 10; z -= 12; v += z; System.out.printf("x = %d y = %d z = %d v = %d%n", x, y, z, v); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-03-2007, 06:06 PM
Member
 
Join Date: Aug 2007
Posts: 2
asterik123 is on a distinguished road
thanks
Hi hardwired,
thanks... I thought so too, without the 2 options i am pretty much at a dead end. now its confirmed!!!
hansneet
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing boolean Values of another values in one class. a_iyer20 Advanced Java 4 04-15-2008 03:04 PM
Controlling method calls bugger New To Java 2 01-04-2008 03:14 PM
JFileChooser remember the location Mr tuition AWT / Swing 3 12-08-2007 07:17 PM
function name osval Advanced Java 1 08-06-2007 10:56 PM
How to access system calls in java Albert New To Java 1 07-13-2007 05:12 PM


All times are GMT +3. The time now is 09:46 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org