Philosopher

Greenhorn
+ Follow
since Mar 15, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Philosopher

Actually, when you call the start() method of the object tc, the object goes to the Ready state and waits for CPU to be allocated to it. So if the CPU gets allocated promptly, the new thread executes the run() method and changes the value of x, in this case you will get the value 10. Now look at the other case, if the new Thread based on tc doesn't get the CPU immediately, the current thread which was executing main method already keeps on going and executes the printout statement. In this case, it prints the value 5 because run() method is not executed yet.
Great question. You need to understand that Java passes arguments by value. A copy of the argument is created and passed to the method. In this code, when another(v,i) is called, compiler internally creates a reference variable which is also pointing to the same object. Here this variable is also named v(This v is in the argument list of another, you can name it anything). Using this v you change the object in the memory to hold the i value equal 20 which was previously 20. Now you make this reference variable point to another memeory object vh which has value 10. When the method returns to the caller, the previous v comes to scope. IT IS NOT THE SAME V IN THE ANOTHER METHOD THAT WAS A COPY OF IT. This v is still pointing to the memory object which has value of i equal 20 thats why it prints 20.
If its not clear still, I will suggest you practice it graphically with a pen and paper with the steps above mentioned. Let me know if you need any further help.
21 years ago
Great question. You need to understand that Java passes arguments by value. A copy of the argument is created and passed to the method. In this code, when another(v,i) is called, compiler internally creates a reference variable which is also pointing to the same object. Here this variable is also named v(This v is in the argument list of another, you can name it anything). Using this v you change the object in the memory to hold the i value equal 20 which was previously 20. Now you make this reference variable point to another memeory object vh which has value 10. When the method returns to the caller, the previous v comes to scope. IT IS NOT THE SAME V IN THE ANOTHER METHOD THAT WAS A COPY OF IT. This v is still pointing to the memory object which has value of i equal 20 thats why it prints 20.
If its not clear still, I will suggest you practice it graphically with a pen and paper with the steps above mentioned. Let me know if you need any further help.
Congratulation. Thanks for sharing the valuable information. Can you also tell how much emphasis is on AWT and events??? and what do you mean by JQ+ questions?
21 years ago
Yeah actually 'this' variable points to the current object for which the method is being executed. For example if you create an object and call a non-static method. 'this' variable will be passed to the method by default and you will be able to use it to access the attributes/operations of the current object for which the method is being executed
21 years ago
In the java ranch game, It says that earlier versions of jdk restricted the programmer to initialize the final member variable within constructor or somewhere but current versions dont. I tried this thing with jdk1.2.2 and it forces me to initialize the final memeber variable. So the answer is TRUE not false. what do you say?
21 years ago