Question 31
Given:
public class Product {
int id; int price;
public Product (int id, int price) {
this.id = id;
this.price = price;
}
Public String toString () { return id + ":" + price;)
}
and the code fragment:
List<Product> products = new ArrayList <> (Arrays.asList(new Product(1, 10), new Product (2, 30), new Product (3, 20)); Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> { p1.price+=p2.price; return new Product (p1.id, p1.price);}); products.add(p); products.stream().parallel()
.reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)
.ifPresent(System.out: :println);
What is the result?
public class Product {
int id; int price;
public Product (int id, int price) {
this.id = id;
this.price = price;
}
Public String toString () { return id + ":" + price;)
}
and the code fragment:
List<Product> products = new ArrayList <> (Arrays.asList(new Product(1, 10), new Product (2, 30), new Product (3, 20)); Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> { p1.price+=p2.price; return new Product (p1.id, p1.price);}); products.add(p); products.stream().parallel()
.reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)
.ifPresent(System.out: :println);
What is the result?
Question 32
Given the code fragment:

Which two code fragments, when inserted at line n1 independently, result in the output PEEK: Unix?

Which two code fragments, when inserted at line n1 independently, result in the output PEEK: Unix?
Question 33
Given:

Which two classes use the shape class correctly?


Which two classes use the shape class correctly?

Question 34
Which two reasons should you use interfaces instead of abstract classes? (Choose two.)
Question 35
Given the following code for a planet object:

And the following main method:

What is the output?


And the following main method:

What is the output?
