aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the out put of this program ? why ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the out put of this program ? why ?" Watch "what is the out put of this program ? why ?" New topic
Author

what is the out put of this program ? why ?

velan vel
Ranch Hand

Joined: Nov 15, 2005
Posts: 137
public class Test2 {



public static void main(String args[]){



Object x = null;

giveMeAString (x);



//First println

System.out.println (x);



me m1 = new me();

m1.f1="Outside method";



testme(m1);

//Last println

System.out.println(m1.f1);



}



public static void giveMeAString(Object y){

y="Iam inside method";

}



public static void testme(me y){

y.f1="modified inside method";

//inside println

System.out.println("Inside "+ y.f1);

}







}



class me{

public String f1=null;

public String f2=null;

}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

What happened when you tried it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

velan please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it.

Also please remove the unnecessary blank lines in the code and indent it properly...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Amrita Udupa
Greenhorn

Joined: Dec 15, 2009
Posts: 2
velan vel wrote:public class Test2 {

public static void main(String args[]){

Object x = null;

giveMeAString (x);

//First println

System.out.println (x);

me m1 = new me();

m1.f1="Outside method";

testme(m1);

//Last println

System.out.println(m1.f1);


}
public static void giveMeAString(Object y){

y="Iam inside method";

}

public static void testme(me y){

y.f1="modified inside method";

//inside println

System.out.println("Inside "+ y.f1);

}

}
class me{

public String f1=null;

public String f2=null;

}

output:
null ( see red)
Inside modified inside method ( see orange)
modified inside method ( see brown)

the comment themselves tell the sequences of the print statements
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the out put of this program ? why ?