Hi all
I have the following code and try to test when references are passed to objects when invoked,but get different output.
When i create one object and want to print out the results i get the results of the method,but when i create another object and pass that objects ref into the method it gives me the output of the first object with the changes.
Can someone please give me clarity on the following code please.
class Record
{
int num;
String name;
public static void testMethod(Record r)
{r.num = 100;
r.name = "Fred";
}
}
public class VariableTest //extends A
{
public static void main(String args[])
{
Record id = new Record();
Record id1 = new Record();
id.num = 100;
id.name = "cornel";
id.testMethod(id1);//here i get different output,but when ref is
//id gives me the result of method
System.out.println(id.name+" " +id.num);
}
}
Thanks for any advice
cornel
I have the following code and try to test when references are passed to objects when invoked,but get different output.
When i create one object and want to print out the results i get the results of the method,but when i create another object and pass that objects ref into the method it gives me the output of the first object with the changes.
Can someone please give me clarity on the following code please.
class Record
{
int num;
String name;
public static void testMethod(Record r)
{r.num = 100;
r.name = "Fred";
}
}
public class VariableTest //extends A
{
public static void main(String args[])
{
Record id = new Record();
Record id1 = new Record();
id.num = 100;
id.name = "cornel";
id.testMethod(id1);//here i get different output,but when ref is
//id gives me the result of method
System.out.println(id.name+" " +id.num);
}
}
Thanks for any advice
cornel