• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the concept behind  RSS feed

 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class ValHold
{
public int i=10;
}
public class MyClass
{
public static void main(String args[])
{
MyClass m=new MyClass();
o.callMe();
}
public void callMe()
{
int i=99;
ValHold v=new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}
public void another(ValHold v,int i)
{
i=0;
v.i=20;
ValHold vh=new ValHold();
v=vh;
System.out.println(v.i);
System.out.println(i);
}
}

why the output is 10 0 30 instead of 20 0 30???
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please format your code -- and use code tags. Generally, when you make it easier for people to read your question, more people will take the time to read your question.

Henry
 
Ulrika Tingle
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Tripathi wrote:why the output is 10 0 30 instead of 20 0 30???


It's because whenever a ValHold Object is created, the i variable will be initialized to 10. And in your code the first output you make is the i variable of a newly created ValHold object, so it's 10.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!