unknown [mailto:[EMAIL PROTECTED]] wrote:
> Can you lemme know the output of the following program and THE REASON ???
Calm down now. Take a few deep breaths. There now. It's a-a-a-a-all going to be
alright. Are you going to be okay?
Okay, now what seems to be the problem here?
> import java.lang.*;
>
> public class Myself
> {
> public static void main(String args[])
> {
> Myself x = new Myself();
> x.doIt();
> }
>
> void doIt()
> {
> int deepak = 10;
> int returnInt = modifyIt(deepak);
> System.out.println("Value is:: "+deepak);
> System.out.println("returnString is:: "+returnInt);
> }
>
> int modifyIt(int x)
> {
> x = 15;
> return x;
> }
> }
>
> =========
>
> I am getting output as 10, 15.
Well then, it seems to me that the output (in full) should be:
-------------------------------
Value is:: 10
returnString is:: 15
-------------------------------
As for the reason, that is quite simple. Java passes variables of primative type
(like "int deepak") to method arguments (line "int x") by value.
For more information, check out the "Language Basics" lesson of the "Learning the Java
Language" trail of Sun's online Java tutorial, here:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html
There. Better now?
-- Roger
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________