Thread: Class help
View Single Post
  #24 (permalink)  
Old 11-15-2007, 06:05 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
A good question. In this method signature
Code:
public myfunct(boolean mybool )
The argument "mybool" is a local variable which has scope limited to the body (curley braces) of the method. In this local scope it hides/shadows the member variable (in class scope) of the same name. So the expected answer is "no."
Let's test it:
Code:
import java.util.Random; public class Test { static Random r = new Random(); static boolean isItTrue = false; static private boolean howBoutThis(boolean isItTrue) { isItTrue = r.nextBoolean(); return isItTrue; } public static void main(String[] args) { Random seed = new Random(); for(int j = 0; j < 5; j++) { boolean b = seed.nextBoolean(); System.out.printf("howBoutThis(%5b) = %5b isItTrue = %b%n", b, howBoutThis(b), isItTrue); } } }
Reply With Quote