Given the code fragment:
int b = 3;
if ( !(b > 3)) {
System.out.println("square ");
}{
System.out.println("circle ");
}
System.out.println("...");
What is the result?
A.
square...
B.
circle...
C.
squarecircle...
D.
Compilation fails.
squarecircle...
Given the code fragment:
What is the result?
A.
20
B.
25
C.
29
D.
Compilation fails
E.
AnArrayIndexOutOfBoundsException is thrown at runtime
20
Given:
public class Emp {
String fName;
String lName;
public Emp (String fn, String ln) {
fName = fn;
lName = ln;
}
public String getfName() { return fName; }
public String getlName() { return lName; }
}
and the code fragment:
List<Emp> emp = Arrays.asList (
new Emp (“John”, “Smith”),
new Emp (“Peter”, “Sam”),
new Emp (“Thomas”, “Wale”));
emp.stream()
//line n1
.collect(Collectors.toList());
Which code fragment, when inserted at line n1, sorts the employees list in descending
order of fName and then ascending order of lName?
A.
sorted
(Comparator.comparing(Emp::getfName).reserved().thenComparing(Emp::getlName))
B.
sorted (Comparator.comparing(Emp::getfName).thenComparing(Emp::getlName))
C.
map(Emp::getfName).sorted(Comparator.reserveOrder())
D.
map(Emp::getfName).sorted(Comparator.reserveOrder().map(Emp::getlName).reserved
sorted
(Comparator.comparing(Emp::getfName).reserved().thenComparing(Emp::getlName))
Given the code fragments:
public class Book implements Comparator<Book> {
String name;
double price;
public Book () {}
public Book(String name, double price) {
this.name = name;
this.price = price;
}
public int compare(Book b1, Book b2) {
return b1.name.compareTo(b2.name);
}
public String toString() {
return name + “:” + price;
}
}
and
List<Book>books = Arrays.asList (new Book (“Beginning with Java”, 2), new book (“A
Guide to Java Tour”, 3));
Collections.sort(books, new Book());
System.out.print(books);
What is the result?
A.
[A Guide to Java Tour:3, Beginning with Java:2]
B.
[Beginning with Java:2, A Guide to Java Tour:3]
C.
A compilation error occurs because the Book class does not override the abstract
method compareTo().
D.
An Exception is thrown at run time.
[A Guide to Java Tour:3, Beginning with Java:2]
Given the class definitions:
What is the result?
A.
Java
Java
Java
B.
Java
Jeve
va
C.
Java
Jeve
ve
D.
Compilation fails
Compilation fails
Page 9 out of 26 Pages |
Previous |