Hi,
        I have a couple of doubts in java. Is it a right place to ask this
type Questions. If not where can I ask ?
        Is java pass arguments to functions PassByValue / PassByReference
        other than primitive datatypes ?
        If PassByRefernce this reference is equivalent to C++ Referencee ?
        pls see the follwoing eg.

class PassBy {

  PassBy() {

    String[] arr = new String[] {"Hi"};
    System.out.println("B4 calling fn, " + arr[0]);
    Call(arr);
    System.out.println("After calling fn, " + arr[0]);
    String str1 = "Ramesh";
    String str2 = "Babu";
    System.out.println("B4 calling fn,1 " + str1 + " 2-- " + str2);
    Swap(str1, str2);
    System.out.println("after calling fn,1 " + str1 + " 2-- " + str2);
    String arr1[] = new String[] {"java"};
    String arr2[] = new String[] {"babu"};
    System.out.println("B4 calling fn,1 " + arr1[0] + " 2-- " + arr2[0]);
    SwapArr(arr1, arr2);
    System.out.println("after calling fn,1 " + arr1[0] + " 2-- " + arr2[0]);
  }

  void SwapArr(String a1[], String a2[]) {

    String[] temp = a1;
    a1[0] = a2[0];
    a2[0] = temp[0];
    System.out.println("In fn,1 " + a1[0] + " 2-- " + a2[0]);

  }

  void Swap(String s1, String s2) {

    String temp = s1;
    s1 = s2;
    s2 = temp;
    System.out.println("In calling fn,1 " + s1 + " 2-- " + s2);

  }

  void Call(String[] local) {
    
    local[0] = "Bye";
    System.out.println("In fn " + local[0]);

  }

  static public void main(String[] args) {

    new PassBy();

  }

}
        
Please explain. Thanks in advance. Bye...

********************************************************************
 Ramesh Babu A.                             Phone 91-44-4909208
 FiLL Project,                              
 TeNet Group,                               <[EMAIL PROTECTED]>
 IIT - Madras.
********************************************************************

Reply via email to