• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

what is the out put of this program ? why ?

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

}
 
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened when you tried it?
 
Sheriff
Posts: 9695
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic