Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 23

Given:

and

What is the result?

    Correct Answer: B

    The code provided defines a class `Person` with a private `String` field named `name` initialized to 'Green.' The `setName` method receives a parameter `name` but shadows the instance variable. It then concatenates 'Mr. ' with the local parameter name, not affecting the instance variable. The `toString` method returns the instance variable `name`, which remains 'Green.' Therefore, when `System.out.println(p);` is called, it outputs 'Green.'

Discussion
RP384Option: B

GREEN will be printed

OmnisumemOption: B

Tested: B.

StavokOption: B

B is correct

Mukes877Option: B

B is correct Because this.name is not used here so the parameter name is changed.

SuperDabichoOption: B

setName() does not change the class variable, it changes the parameter name.

Leksh_geethOption: B

Correct Answer is Option B

aruni_mishraOption: B

Tested: B

d7bb0b2Option: B

B is correct, setName(string name) shadow instance variable, not modified, if had another name this variable in mehtod setName(String otherName), then name of instance is modified. So print only "GREEN"

JGR_77Option: B

Greenwill be printed

NokuLOption: C

c is correct

UcefSoftOption: B

B is correct