Hi, I think i know the answer to the second one. It is because the variable is static the variable belongs to the class and not to the object so the variable value is what you assign to it last, which is 20.

The answer is 0, because x still refers to an Integer object with value 10, and the object reference pointed to by y still refers to an Integer object with value 99. Setting z=null does not make any object eligible for GC. [ July 08, 2005: Message edited by: Kedar Dravid ]

As long as an object has a live thread referencing it, the object will not become eligible for garbage collection. In case of question 1 the reference x is passed to a method. Objects are passed by reference so a copy of the reference was passed. That copy in the method became null while the original reference still was attached to the object. Same case applies to reference y.

I try not to make questions available without including an explanation of the answer. In the case of that first question I have included the explanation ...

"A reference passed into a method is passed as if it were a copy of a pointer pointer rather than the actual object. Thus if that reference is assigned to a null it makes no difference to any other copy of that pointer. Thus the code within the method findOut makes no difference to any other references. Although reference z is assigned to null reference y still points to the object so no objects are eligible for garbage collection."

Was this explanation availible/visible/correct/meaningful. Your feedback is greatly appreciated.

(This question is one that is publicly visible from the database at http://www.jchq.net/phezam and is from the JDK1.4 subject set) Marcus [ July 08, 2005: Message edited by: Marcus Green ]

I am getting the following exception when I try to compile the above Code

Exception in thread "main" java.lang.NoClassDefFoundError: Csturt (wrong name: C Sturt) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12 3) at java.net.URLClassLoader.defineClass(URLClassLoader.java:251) at java.net.URLClassLoader.access$100(URLClassLoader.java:55) at java.net.URLClassLoader$1.run(URLClassLoader.java:194) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:187) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

Originally posted by latha yeduguri: I am getting the following exception when I try to compile the above Code

Exception in thread "main" java.lang.NoClassDefFoundError: Csturt (wrong name: C Sturt) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12 3) at java.net.URLClassLoader.defineClass(URLClassLoader.java:251) at java.net.URLClassLoader.access$100(URLClassLoader.java:55) at java.net.URLClassLoader$1.run(URLClassLoader.java:194) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:187) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)