Given the definition of the Vehicle class:
class Vehicle {
String name;
void setName (String name) {
this.name = name;
}
String getName() {
return name;
}
}
Which action encapsulates the Vehicle class?
A.
Make the Vehicle class public.
B.
Make the name variable public.
C.
Make the setName method public.
D.
Make the name variable private.
E.
Make the setName method private.
F.
Make the getName method private.
Make the name variable public.
Given the code fragment:
List<String> empDetails = Arrays.asList(“100, Robin, HR”,
“200, Mary, AdminServices”,
“101, Peter, HR”);
empDetails.stream()
.filter(s-> s.contains(“1”))
.sorted()
.forEach(System.out::println); //line n1
What is the result?
A.
100, Robin, HR
101, Peter, HR
B.
A compilation error occurs at line n1.
C.
100, Robin, HR
101, Peter, HR
200, Mary, AdminServices
D.
100, Robin, HR
200, Mary, AdminServices
101, Peter, HR
A compilation error occurs at line n1.
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 = Arrays.asList(new Product(1, 10),
new Product (2, 30),
new Product (2, 30));
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?
A.
2 : 30
B.
4 : 0
C.
4 : 60
D.
4 : 60
2 : 30
3 : 20
1 : 10
E.
The program prints nothing.
4 : 60
2 : 30
3 : 20
1 : 10
Given the code fragment:
List<Integer> values = Arrays.asList (1, 2, 3);
values.stream ()
.map(n -> n*2)//line n1
.peek(System.out::print)//line n2
.count();
What is the result?
A.
246
B.
The code produces no output.
C.
A compilation error occurs at line n1.
D.
A compilation error occurs at line n2.
246
Given the fragments
Which line causes a compilation error?
A.
Line n1
B.
Line n2
C.
Line n3
D.
Line n4
Line n1
Page 2 out of 26 Pages |
Previous |