Given:
and
What is the result?
Given:
and
What is the result?
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.'
GREEN will be printed
Tested: B.
B is correct
B is correct Because this.name is not used here so the parameter name is changed.
setName() does not change the class variable, it changes the parameter name.
Correct Answer is Option B
Tested: 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"
Greenwill be printed
c is correct
B is correct