class Bar{
int barNum=28;
}
class Foo{
Bar myBar = new Bar();
void changeIt(Bar myBar){ //Here is object's reference is passed or the object is passed?
myBar.barNum = 99;
System.out.println("myBar.barNum in changeIt is " + myBar.barNum);
myBar = new Bar(); //Is the old myBar object destroyed now and new myBar is referring to something new now?
myBar.barNum = 420;
System.out.println("myBar.barNum in changeIt is now "+myBar.barNum);
}
public static void main(String args[]){
Foo f = new Foo();
System.out.println("f.myBar.barNum is "+f.myBar.barNum); //Explain f.myBar.barNum!
f.changeIt(f.myBar); //f.myBar refers to the object right? but we need to pass reference of the type Bar in changeIt!?
System.out.println("f.myBar.barNum after changeIt is "+ f.myBar.barNum); //How do you decide f will call which myBar.barNum?
}
}
Explain the questions mentioned in the comments please The output of the code is f.myBar.barNum is 28 myBar.barNum in changeIt is 99 myBar.barNum in changeIt is now 420
f.myBar.barNum after changeIt is 99