Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 130

Given the code fragments :

and

What is the result?

    Correct Answer: A

    The result prints the updated prices for both products. The code first creates a list of products with initial prices of 1000 and 2000. Then, it applies a Consumer function to each product in the list, increasing each price by 100. Finally, it prints out each product's updated price. Therefore, The prices are updated from 1000 to 1100 for the TV and from 2000 to 2100 for the Refrigerator. Thus, the output is 'TV Price: 1100 Refrigerator Price: 2100.'

Discussion
AVB22Option: A

A is correct TV Price: 1100Refrigerator Price: 2100 class Product { String name; Integer price; Product(String name, Integer price){ this.name = name; this.price = price; } public void printVal() {System.out.print(name + " Price: "+ price);} public void setPrice(int price) {this.price = price;} public Integer getPrice() {return price;} } public class Test { public static void main (String[] args) { List<Product> li = Arrays.asList(new Product ("TV",1000), new Product ("Refrigerator",2000)); Consumer<Product> raise = e->e.setPrice(e.getPrice()+100); li.forEach(raise); li.stream().forEach(Product::printVal); }}

lnrdgstOption: A

The answer is "A". However, there was a typo in the alternatives, it should contain TV Price:1100 Refrigerator Price:2100 instead of TV Price :110 Refrigerator Price :2100

steefaandOption: A

A is correct, but there is typo in answer and it should be TV Price :1100

OhayouOption: A

Answer : A