Page 1 of 1
About Question enthuware.ocajp.i.v7.2.974 :
Posted: Sat Mar 08, 2014 1:43 pm
by fasty23
The book explained very well but for more understanding (as I'm lame in JAVA)

let me ask:
s1 changed because x1 used a method? (x1 still use same reference of s1 because x1 changed by a method not by assignment operator)?
s2 does not changed because x2 use "=" operator? (x2 point to another reference in memory immediately after it use "=" operator.) so x2 does not change the s2 reference?
Re: About Question enthuware.ocajp.i.v7.2.974 :
Posted: Sat Mar 08, 2014 9:30 pm
by admin
Yes, that is correct.
Re: About Question enthuware.ocajp.i.v7.2.974 :
Posted: Tue Dec 02, 2014 2:45 pm
by gparLondon
Are such questions there in the exam? I was searching for Stack class code, and ran out of time.
Re: About Question enthuware.ocajp.i.v7.2.974 :
Posted: Tue Dec 02, 2014 8:50 pm
by admin
Yes, very likely. It has nothing to do with Stack class though. If you are searching for Stack class code, you are going in the wrong direction. All the information that is necessary to answer this question is provided in the question itself.
Re: About Question enthuware.ocajp.i.v7.2.974 :
Posted: Thu Dec 29, 2016 6:56 pm
by JavaJunky
Thanks Paul for the good explanation. This is great
Re: About Question enthuware.ocajp.i.v7.2.974 :
Posted: Mon Jun 05, 2017 1:04 am
by JavaSoftware
package myPackage;
public class Person {
private String name;
public void getName(){
System.out.println(this.name);
}
public Person(String name){
this.name = name;
}
}
package myPackage;
public class TestEnthuwhare {
public static void main(String[] args){
Person p1 = new Person("Ben");
Person p2 = new Person("Peter");
printPersons(p1, p2);
p2.getName();
}
public static void printPersons(Person p, Person p2){
p.getName();
p2.getName();
p2 = p;
p2.getName();
}
}
Result is:
Ben
Peter
Ben // instead Peter
Peter // and outside the reference don't change
It might be helpfull

Re: About Question enthuware.ocajp.i.v7.2.974 :
Posted: Mon Jun 05, 2017 1:26 am
by admin
Very good

Re: About Question enthuware.ocajp.i.v7.2.974 :
Posted: Tue Nov 27, 2018 9:13 pm
by ash4413
Perfect explanation
Thanks