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

Given:

and

What is the result?

    Correct Answer: C

    The given code initializes a Person object with the name 'Joe', invokes the checkPerson method on this object, and prints the object's state. Since checkPerson doesn't modify the original object reference, the name remains 'Joe'. The second part sets the object reference to null, and checkPerson creates a new Person object with the name 'Mary', although the returned new object reference is ignored, so the name remains null. Thus, the output is 'Joe' in the first print statement and 'null' in the second print statement.

Discussion
JGR_77Option: B

b: public static void main(String[] args) { String s = "joe"; System.out.println(checkPerson(s)); s= null; System.out.println(checkPerson(s)); } public static String checkPerson(String s) { if(s==null) { s= "mary"; }else {s= null;} return s; } null mary

Ankit1010Option: A

A is the correct Answer

duydnOption: A

class Person{ private String name; public Person(String name) { this.name = name; } public String toString() { return name; } } class Test { public static void main(String[] args) throws IOException { Person p = new Person("Joe"); checkPerson(p); System.out.println(p); p=null; checkPerson(p); System.out.println(p); } public static Person checkPerson(Person p) { if (p == null) { p = new Person("Mary"); } else { p = null; } return p; } } -> A

[Removed]Option: A

It's A. If it would have been p = checkPerson(p); Then correct answer would have been answer Null and then Mary. Now it's just checkPerson(p) so p remains "Joe" and then Null.

great_chainickOption: B

1th checkperson transforms joe to null , so system.out.print print null 2th checkperson recieve null and transforms this null to mary , so system.out.print print in the console "mary"

Mukes877Option: A

A is correct because Changes in references of Person p are in the Person class so that object has different scope So There will be no effect on the Tester class object.

d7bb0b2Option: A

A is correct, check person never modified value for p so take the values from main method

Javi_scOption: A

A is correct

StavokOption: A

A is CORRECT

aruni_mishraOption: B

B. Correct

AlanRMOption: A

is correct A