[HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

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

Moderator: admin

Post Reply
OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

[HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Post by OCAJO1 »

page 76, "Working with Methods and Encapsulation" chapter . &

Chapter 8 makes much better reference variable to the address of "Working with Methods and Encapsulation" than Chapter . & :D

Page 76, 1. this is a keyword. That means you can't use it as variable name or class name.

I was wondering, shouldn't this sentence also include method name?

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

Re: [HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Post by admin »

OCAJO1 wrote:
Fri Jan 11, 2019 2:58 pm
page 76, "Working with Methods and Encapsulation" chapter . &
Chapter 8 makes much better reference variable to the address of "Working with Methods and Encapsulation" than Chapter.
Yes, it seems the chapter numbers were not decided when it was written. Even so, the sentence is ok, "...the "Working with Methods and Encapsulation" chapter.", implies the chapter with title "Working with Methods and Encapsulation" :)

Page 76, 1. this is a keyword. That means you can't use it as variable name or class name.

I was wondering, shouldn't this sentence also include method name?
and may be interface name, enum name, and package name also :D But yes, the sentence could be restructured to make it more clear.
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Post by Username987654 »

given
The compiler does not execute any code and it has no knowledge of the values that a variable might take during the execution of the program.
But when you do name = name;, the compiler cannot distinguish between the two name variables. It thinks that name refers to the method parameter and assigns the value of the method parameter to itself, which is basically redundant and is not what you want.
should be
But when you do name = name;, the compiler cannot distinguish between the two name variables. It thinks that name refers to the method parameter and the JVM (later) assigns the value of the method parameter to itself, which is basically redundant and is not what you want.
?

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

Re: [HD Pg 75, Sec. 3.4.2 - when-is-this-necessary]

Post by admin »

No, this is fine. It is talking about what the compiler understands by name = name. The code name = name; implies that you are assigning the name to name. The actual assignment of the value is, of course, done by the JVM at runtime but the bytecode for that assignment is generated by the compiler.

In other words, " assigns the value of the method parameter to itself," means "the compiler generates the byte code that assigns the value of the method parameter to itself".
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 57 guests