• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the out put of this program ? why ?

 
velan vel
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Amrita Udupa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 246
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic