On Wed, Feb 27, 2002 at 07:10:08PM +0530, Sandip Bhattacharya wrote:
| "st1" in "Method" is just a *local-variable* where a memory location is stored -

I am not sure if I still get it. Following is the Method:

 private void Method(Stack st1,Stack st2) {
  st2.push(new Integer(100));
  st1 = st2;
  System.out.println("st1 has: "+st1);
  System.out.println("st2 has: "+st2);
 }

The Method() gets st1, and st2 as parameters to the method. Since in
Java, we have parameters passed by reference, st2.push() is able to
modify st2. Now if I had st1.push(), then st1 would have been modified
and the effect would be seen in the main().

| initially this has the memory address of main:st1 and later on
| overwritten by the memory address of st2 or main:st2.

This is true. st1 is overwritten by memory address of st2 or main:st2.
So why doesn't it retain the assignment after it returns from Method()?
I guess, the OP wanted to know that.

chyrag.
-- 
Chirag Kantharia, symonds.net/~chyrag/
Linux scrooge 2.4.17 #1 Wed Jan 16 17:07:25 IST 2002 i686 unknown

          ================================================
To subscribe, send email to [EMAIL PROTECTED] with subscribe in subject header
To unsubscribe, send email to [EMAIL PROTECTED] with unsubscribe in subject header
Archives are available at http://www.mail-archive.com/ilugd%40wpaa.org
          =================================================

Reply via email to