Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 75

Given:

What is the result?

    Correct Answer: C

    The result is false:true. In the code, the comparison p1 == p2 evaluates to false because p1 and p2 are two different objects, even though they have the same values for their fields. Object comparison with '==' checks for reference equality, not value equality. The comparison p1.name.equals(p2.name) evaluates to true because the equals method of the String class compares the actual content of the strings, and both names are 'Pen'.

Discussion
dya45792Option: C

Antwort C, ist richtig public class Product { int id; String name; public Product (int id, String name) { this.id = id; this.name = name; } public static void main(String[] args) { Product p1 = new Main (101, "Pen"); Product p2 = new Main (101, "Pen"); Product p3 = p1; boolean ans1 = p1 == p2; boolean ans2 = p1.name.equals(p2.name); System.out.println(ans1 + " : " + ans2); } } false : true

JoseCG

Correct.

98RohitsahuOption: C

Correct Answer is C.

dsmsOption: C

correct answer is C: false:true

dsmsOption: C

boolean ans1 = p1 == p2; // false - because p1 and p2 is two different objects boolean ans2 = p1.name.equals(p2.name); // true

Vicky_65Option: C

correct one is C

CreazyyyyGirlOption: C

C is correct

SolliiiOption: D

tested: class Product { int id; String name; public Product(int id, String name) { this.id = id; this.name = name; } public static void main(String[] args) { Product p1 = new Product(101, "Pen "); Product p2 = new Product(101, "Pen"); Product p3 = p1; boolean ans1 = p1 == p2; boolean ans2 = p1.name.equals(p2.name); System.out.print(ans1 + " " + ans2); } }

Mtandwa

Unfortunately you added a space after Pen in p1 that's why the answer came out as false. answer is C

RipfumeloOption: C

The answer is C:tested and proven

haisacoOption: C

c is correct

anmoldev2javaOption: C

c is correct

carlosworkOption: C

Answer is C. class Product { int id; String name; public Product(int id, String name) { this.id = id; this.name = name; } public static void main(String[] args) { Product p1 = new Product(101, "Pen"); Product p2 = new Product(101, "Pen"); Product p3 = p1; boolean ans1 = p1 == p2; boolean ans2 = p1.name.equals(p2.name); System.out.print(ans1 + " " + ans2); } }

DiamondWhiteOption: D

Actually it's false false, because the first name has a white space "Pen ".. while the other name is "Pen"..

DiamondWhite

Oops ignore my comment...

neredynerdOption: D

Answer D false false checked class Product { int id; String name; public Product(int id, String name) { this.id = id; this.name = name; } public static void main(String[] args) { Product p1 = new Product(101, "Pen "); Product p2 = new Product(101, "Pen"); Product p3 = p1; boolean ans1 = p1 == p2; boolean ans2 = p1.name.equals(p2.name); System.out.print(ans1 + " " + ans2); } }

DiamondWhite

You have a white space in the first name "Pen "

BradleyyeoOption: D

equals method not overriden so should be false:false right?

shivkumarx

ans2 is comparing the name property not the object itself so its true that "Pen".equals("Pen")

Ghamm

Yes, i am agree with you. But when I compiled the correct option is C only.

Yogesh_gavate19Option: D

false false

Rupesh46Option: C

Line 7 is comparing the objects, not the content of objects, so that is false.