Results 1 to 2 of 2
  1. #1
    syntrax is offline Member
    Join Date
    Sep 2009
    Location
    http://www.kouje.com
    Posts
    16
    Rep Power
    0

    Arrow entities are passed by value or passed by reference

    Are these past by "Value" or "Reference"?


    Integer variables are passed by:
    Value
    Integer arrays are passed by:
    Value
    String variables are passed by:
    Value
    Object variables are passed by:
    Value

    i'm saying that they are passed by Value, right?

    ps.
    i know the code seems wierd or coded like a wth,,, but it was provided by my instructor. I'm guessing trying to make things tricky?

    Java Code:
    /**
     * @author Carlos Saavedra
     * @version 8.1.5 2009/12/15
     */
    
    public class Assignment8_B 
    {
        public static void main(String[] args) 
        {
            int int_test = 10;
            int int_array[] = {100, 200, 300};
            String str_test = "CIS 150";
            MyClass object_test = new MyClass("Carlos", 15);
            
            System.out.println("int_test BEFORE method call...\t\t" + int_test);
            test_passing_int(int_test);
            System.out.println("int_test AFTER method call...\t\t" + int_test);
            
            print_array(int_array, "Int_array BEFORE  method call...\t");
            test_passing_array(int_array);
            print_array(int_array, "int_array AFTER method call.....\t");
            test_passing_array(int_array);
            
            System.out.println("str_test BEFORE method call...\t\t" + str_test);
            test_passing_String(str_test);
            System.out.println("str_test AFTER method call...\t\t" + str_test);
            
            System.out.println("object_test BEFORE method call...\t" + object_test.toString());
            test_passing_object(object_test);
            System.out.println("object_test AFTER method call...\t" + object_test.toString());
        }
        
        public static void test_passing_int(int _i)
        {
        	_i *= 2;
        }
        
        public static void print_array(int _arr[], String msg)
        {
        	System.out.print(msg);
        	for(int i=0; i<_arr.length; i++)
        		System.out.print(_arr[i] + "\t");
        	
        	System.out.println();
        }
        
        public static void test_passing_array(int _arr[])
        {
        	for(int i=0; i < _arr.length; i++)
        		_arr[i] *= 2;
        }
        
        public static void test_passing_String(String _str)
        {
        	_str = "CIS150";
        }
        
        public static void test_passing_object(MyClass _obj)
        {
        	_obj.setNameHours("Pam\t", 16);
        }
    }
    MyClass:
    Java Code:
    public class MyClass
    {
    	String name;
    	int hours;
    	
    	public MyClass(String _name, int _hours)
    	{
    		name = _name;
    		hours = _hours;
    	}
    	
    	public void setNameHours(String _name, int _hours)
    	{
    		name = _name;
    		hours = _hours;
    	}
    	
    	public String toString()
    	{
    		return "Name: " + name + "\tHours: " + hours;
    	}
    }
    Last edited by syntrax; 12-17-2009 at 02:50 AM.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

Similar Threads

  1. Replies: 7
    Last Post: 12-16-2009, 11:51 AM
  2. java certification passed
    By natasha in forum Java Certification
    Replies: 0
    Last Post: 12-05-2009, 08:24 AM
  3. Cannot get passed these syntax errors
    By MrKP in forum New To Java
    Replies: 1
    Last Post: 05-12-2008, 07:05 AM
  4. Null array when passed to MouseListener
    By stevemcc in forum New To Java
    Replies: 2
    Last Post: 04-02-2008, 10:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •