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

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

Moderator: admin

Post Reply
admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Not sure what are you asking.
Paul.
If you like our products and services, please help us by posting your review here.

pupmonster
Posts: 1
Joined: Thu Jul 20, 2017 11:32 am
Contact:

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

Post by pupmonster »

>>>> See above , only 2 objects are created
>>>> 1) 3dccbdf7 (t1 and t2 referring same object)
>>>> 2) 4ccbc2d3
>>>> and 3 references t.e., t1, t2, and t3.

>> You are right.

Could the answer possibly be corrected in the next version?

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

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

Post by admin »

Ok, I see the confusion now.

No distinction is made between a reference and reference variable in Java because unlike c/c++, which has the concept of pointers as well as references, Java has only one thing - references. Each reference variable in Java stores a value - either that value is the address to an object or that value represents null.

For this reason, the term reference and reference variable are interchangeable in Java.

Therefore, in this case, there are 4 references (not three). t4 is not pointing to the same object as t1, t2, and t3 are pointing to, but t4 is a reference nonetheless, pointing to null.
If you like our products and services, please help us by posting your review here.

igor.simecki
Posts: 5
Joined: Tue Feb 06, 2018 2:41 am
Contact:

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

Post by igor.simecki »

admin wrote:Ok, I see the confusion now.

No distinction is made between a reference and reference variable in Java because unlike c/c++, which has the concept of pointers as well as references, Java has only one thing - references. Each reference variable in Java stores a value - either that value is the address to an object or that value represents null.

For this reason, the term reference and reference variable are interchangeable in Java.

Therefore, in this case, there are 4 references (not three). t4 is not pointing to the same object as t1, t2, and t3 are pointing to, but t4 is a reference nonetheless, pointing to null.
except reference variables in methods, in which case t4 doesn't store anything and will not compile if used.

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

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

Post by admin »

igor.simecki wrote:
admin wrote:Ok, I see the confusion now.

No distinction is made between a reference and reference variable in Java because unlike c/c++, which has the concept of pointers as well as references, Java has only one thing - references. Each reference variable in Java stores a value - either that value is the address to an object or that value represents null.

For this reason, the term reference and reference variable are interchangeable in Java.

Therefore, in this case, there are 4 references (not three). t4 is not pointing to the same object as t1, t2, and t3 are pointing to, but t4 is a reference nonetheless, pointing to null.
except reference variables in methods, in which case t4 doesn't store anything and will not compile if used.
Not sure what you mean. t4 is a reference variable. No matter whether it is used or not or where is it used. Can you post some code to show what you mean exactly?
If you like our products and services, please help us by posting your review here.

igor.simecki
Posts: 5
Joined: Tue Feb 06, 2018 2:41 am
Contact:

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

Post by igor.simecki »

void test(){
Object o1,o2;
o1= new Object();
o2.toString();
}

this will cause a compiler error because o2 references nothing.

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

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

Post by admin »

igor.simecki wrote:void test(){
Object o1,o2;
o1= new Object();
o2.toString();
}

this will cause a compiler error because o2 references nothing.
Did you read the error message that the compiler generated when you tried to compile the above code? The error is not because o2 points to nothing. The error is because you are trying to use o2 without initializing it. Try o2 = null; first and then see what happens.

Regardless, o2 is still a valid reference variable.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 101 guests