[program-java] Re: Java: Precedence... solution

  • From: "Homme, James" <james.homme@xxxxxxxxxxxx>
  • To: "program-java@xxxxxxxxxxxxx" <program-java@xxxxxxxxxxxxx>
  • Date: Fri, 17 Sep 2010 14:53:56 -0400

Hi,
What makes x global?

Thanks.

Jim

Jim Homme,
Usability Services,
Phone: 412-544-1810. Skype: jim.homme
Internal recipients,  Read my accessibility blog. Discuss accessibility here. 
Accessibility Wiki: Breaking news and accessibility advice


-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Friday, September 17, 2010 2:52 PM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Re: Java: Precedence... solution

That's what I was trying to point out that the global x had the focus so to 
speak. Yes, I was counting on my fingers and since I had one bit off by a shark 
a few years back I live in base 9.

Jim

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Sina Bahram
Sent: September 17, 2010 14:12
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Java: Precedence... solution

No, because there's no int specification in the for loop ... That x is the 
global x.

Also, it gets incremented to 10, not 9.

Take care,
Sina
________________________________

From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Friday, September 17, 2010 2:07 PM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Java: Precedence... solution


Hey now:

I've finally resolved the issue I was having with variables being reused 
multiple times in the same class...

For the sake of brevity:

Public class MyClass {

Private int x = 1;

Public MyClass() {
myMethod();
}

Private void myMethod() {
For (x =0; x<10; x++) {
}
}
}

...obviously x gets finally incremented to 9 and since it's global then it 
throws off any reuse of the variable.

James M. Corbett

Programmer / Analyst |
Canada Revenue Agency | Agence du revenue du Canada
875 Heron Rd.
Ottawa, On.
K1A0L5

James.Corbett@xxxxxxxxxxxxx
Telephone | Téléphone: (613) 941-1338
Facsimile | Télécopieur: (613) 941-2261

Government of Canada | Gouvernement du Canada





This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed.  If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it.  If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
 The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.

Other related posts: