/* Author : Michael Robinson Program : theThis.java Purpose : To show how to use the "this" command to select global and local variables Updated : August 18th, 2099 */ public class theThis { private int number = 5; private String name = "Donald"; private String major = "Computer Science"; //method test2 accepts variables that have the same name as the //above global variables. public void test2( int number, String name, String major ) { //the variables with the this command prior to its name is //referring to the global variable. The variable without //the this command is the local variable accepted by this //method. System.out.println( this.number + " is not the same as " + number); System.out.println( this.name + " is not the same as " + name); System.out.println( this.major + " is not the same as " + major); System.out.println( "The 'this' variables refer to the" + " class global variables." ); }//end public void test2( int number, String name, String major ) public void test1() { int number = 4; System.out.println( "Local: " + number ); System.out.println( "Global: " + this.number ); test2( 22, "Joe", "Computer Engineering" ); }//end public void test1() public static void main( String arg[] ) { //creates an instance of this class/program //and calls the test2 method new theThis().test1(); }//end public static void main( String arg[] ) }//end public class theThis