About Question enthuware.ocajp.i.v7.2.974 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
fasty23
Posts: 37
Joined: Thu Feb 13, 2014 12:58 am
Contact:

About Question enthuware.ocajp.i.v7.2.974 :

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.974 :

Post by admin »

Yes, that is correct.

gparLondon
Posts: 63
Joined: Fri Oct 31, 2014 6:31 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.974 :

Post by gparLondon »

Are such questions there in the exam? I was searching for Stack class code, and ran out of time.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.974 :

Post 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.

JavaJunky
Posts: 4
Joined: Wed Dec 14, 2016 11:07 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.974 :

Post by JavaJunky »

Thanks Paul for the good explanation. This is great

JavaSoftware
Posts: 6
Joined: Sat Jun 03, 2017 1:43 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.974 :

Post 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 :)

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.974 :

Post by admin »

Very good :)

ash4413
Posts: 4
Joined: Thu Jul 26, 2018 7:48 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.974 :

Post by ash4413 »

Perfect explanation

Thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests