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

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

Moderator: admin

Post Reply
shamran99
Posts: 15
Joined: Wed May 10, 2017 2:49 am
Contact:

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

Post by shamran99 »

Hi,

I just want to know is arrays the only one will be pass by reference?

Regards,
Shamran.

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

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

Post by admin »

No, in Java, everything is passed by value. But in case of objects (any object, including arrays) it is the value of the reference that is passed by value. It is a very important topic so I will suggest you to go through a good book to understand it. Here are a few good links -

http://javadude.com/articles/passbyvalue.htm
and
http://stackoverflow.com/questions/4048 ... s-by-value
If you like our products and services, please help us by posting your review here.

horst1a
Posts: 37
Joined: Mon Jun 12, 2017 2:16 am
Contact:

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

Post by horst1a »

And why does the compiler not put an implicit this before the c in m2()

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

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

Post by admin »

horst1a wrote:And why does the compiler not put an implicit this before the c in m2()
Because a variable named c is already in scope. The compiler tries using "this" (or the classname to use the static variable) only if it is not able to resolve the given variable. Here, it is already able to resolve c as a method parameter. So there is no need to use "this".

HTH,
Paul.
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 59 guests