× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



In general the answer is no. Method variables are local to the method and
cannot be access from anywhere else. This is exactly the same as with
subprocedure variables in RPG.

To make your example work, make the variable global (private to stop
anything outside this class accessing it, and static because both your
methods are static) :

private static DB2400 nal820;

public static void main(String args[]) {
  nal820 = new DB2400("nal820");
  getData(nal820);
  nal820.disconnect();
}

public static void getData(DB2400 nal820) {
  //process data
}

Hope this helps,
Chris.

-----Original Message-----
From: Shane_Cessna@xxxxxxx [mailto:Shane_Cessna@xxxxxxx]
Sent: 13 June 2005 14:52
To: JAVA400-L@xxxxxxxxxxxx
Subject: "new to Java" question...


Is there an easier way to access method variables in another method other 
than passing them on the call?  here's an example:

public static void main(String args[]) {
  DB2400 nal820 = new DB2400("nal820");
  getData(nal820);
  nal820.disconnect();
}

public static void getData(DB2400 nal820) {
  //process data
}

could I do something in the getData method to access my "nal820" variable 
without passing it?  I'm sure it's something really easy and basic, but 
like the subject says, it's a "new to Java" type of question...Thanks...

Shane Cessna
iSeries Programmer
iSeries WAS Administrator
North American Lighting, Inc.
(618) 662-4483 x2776
shane_cessna@xxxxxxx

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.