> Hi,
>     I have doubt that java passes arguments(for objects) by reference ?
>
>     If yes then
>         this pass by reference is equals to c++ reference.
>
>     and tell wihch are all objects ? (Strings are objects ???)
>
>     I have sample prog. which makes to confuse.
>     please explain clearly
>
> ------------------------------------------------------------------
>
> class PassBy {
>     public PassBy()
> {
>      //Button
>     Button b = new Button("Test");
>     System.out.println("B4 calling fun label " + b.getLabel());
>     fun(b);
>     System.out.println("after calling fun label " + b.getLabel());
>
>     // --------------------------------------
>     // array
>     String[] arr = new String[] {"Hi"};
>     System.out.println("B4 calling fn, " + arr[0]);
>     Call(arr);
>     System.out.println("After calling fn, " + arr[0]);
>
>     // --------------------------------------
>
>     // String
>     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);
>
>   // i don't know
>     Integer int1 = new Integer(444);
>     Integer int2 = new Integer(666);
>     System.out.println("B4 swapping 1---- " + int1 + " 2 --- " + int2);
>     SwapInt(int1, int2);
>     System.out.println("after swapping 1---- " + int1 + " 2 --- " +
> int2);
>   }
>
>   private void fun(Button c) {
>
>     System.out.println("In fun, Label " + c.getLabel());
>     c.setLabel("Hooooooo");
>     System.out.println("In fun, after setting " + c.getLabel());
>   }
>
>   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]);
>
>   }
>
>   void SwapInt(Integer int1, Integer int2) {
>     Integer temp = int1;
>     int1 = int2;
>     int2 = temp;
>     System.out.println("In fn, after swapping 1---- " + int1 + " 2 --- "
> + int2);
>
>   }
>
>   static public void main(String[] args) {
>
>     new PassBy();
>
>   }
>
> }


Reply via email to