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

Given:

What is the result?

    Correct Answer: C

    C

Discussion
iSnoverOption: C

The answer is C. even p1 having the same content as lst[0], they are different objects so it will return "-1" which is what it returns when we use the "indexOf" constructor and we don't find anything equal to the parameter we used.

Jess1985BOption: C

Since p1 is not added to previous list so if you try accessing its Index position it would give you -1.

carlosworkOption: C

Answer is C. To test: import java.util.ArrayList; import java.util.List; class Product { int id; String name; Product (int id, String name){ this.id = id; this.name = name; } } public class Test { public static void main(String[] args) { List <Product> Ist = new ArrayList<>(); Ist.add(new Product(10, "IceCream")); Ist.add(new Product(11, "Chocolate")); Product p1 = new Product(10, "IceCream"); System.out.println(Ist.indexOf(p1)); } }