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));
}
}
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.
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Jess1985B
3 weeks agocarloswork
1 year, 1 month agoiSnover
1 year, 2 months ago