Calling Methods Exercises

  < Previous  Next >
  1. What will be the output of the code below? Why?
    public class ArgumentParameterExample{                    // Line  1
    							  // Line  2 
        public static void paramTest( int num, String msg ){  // Line  3
    	num = 42;					  // Line  4 
    	msg = "All your base are belong to us";		  // Line  5
        }							  // Line  6 
        							  // Line  7 
        public static void main(String[] args){		  // Line  8 
    	int value = 1;					  // Line  9 
    	String str = "hello, world";			  // Line 10
    							  // Line 11
    	paramTest( value, str );			  // Line 12
    							  // Line 13
    	System.out.println( value );			  // Line 14
    	System.out.println( str );			  // Line 15
        }							  // Line 16
    }                                                         // Line 17
    
  2. Storing Primitive and Reference Variables:
    Using the Stack Frame and Heap below, diagram how each of the variables above is stored and referenced.
    Empty stack frame and heap
  3. For each of the variables above, list the line numbers that correspond with their scope.