Given the code fragments:
class Employee { Optional
address;Employee (Optional
address) {this.address = address;
}
public Optional
getAddress() { return address; }}
class Address {
String city = "New York";
public String getCity { return city: }
public String toString() {
return city;
}
}
and
Address address = null;
Optional
addrs1 = Optional.ofNullable (address);Employee e1 = new Employee (addrs1);
String eAddress = (addrs1.isPresent()) ? addrs1.get().getCity() : "City Not
available";
What is the result?
A. New York
B. City Not available
C. null
D. A NoSuchElementException is thrown at run time.
Given that course.txt is accessible and contains:
Course : : Java
and given the code fragment:
public static void main (String[ ] args) { int i; char c; try (FileInputStream fis = new FileInputStream (“course.txt”);
InputStreamReader isr = new InputStreamReader(fis);) {
while (isr.ready()) { //line n1
isr.skip(2);
i = isr.read ();
c = (char) i;
System.out.print(c);
} } catch (Exception e) { e.printStackTrace(); } }
What is the result?
A. ur :: va
B. ueJa
C. The program prints nothing.
D. A compilation error occurs at line n1.
Given:
public class Canvas implements Drawable {
public void draw () { }
}
public abstract class Board extends Canvas { }
public class Paper extends Canvas {
protected void draw (int color) { }
}
public class Frame extends Canvas implements Drawable {
public void resize () { }
}
public interface Drawable {
public abstract void draw ();
}
Which statement is true?
A. Board does not compile.
B. Paper does not compile.
C. Frame does not compile.
D. Drawable does not compile.
E. All classes compile successfully.
Which statement is true about the single abstract method of the java.util.function.Function interface?
A. It accepts one argument and returns void.
B. It accepts one argument and returns boolean.
C. It accepts one argument and always produces a result of the same type as the argument.
D. It accepts an argument and produces a result of any data type.
For which three objects must a vendor provide implementations in its JDBC driver? (Choose three.)
A. Time
B. Date
C. Statement
D. ResultSet
E. Connection
F. SQLException
G. DriverManager
Given:
interface Doable {
public void doSomething (String s);
}
Which two class definitions compile? (Choose two.)
A. public abstract class Task implements Doable { public void doSomethingElse(String s) { } }
B. public abstract class Work implements Doable { public abstract void doSomething(String s) { } public void doYourThing(Boolean b) { } }
C. public class Job implements Doable {
public void doSomething(Integer i) { }
}
D. public class Action implements Doable { public void doSomething(Integer i) { } public String doThis(Integer j) { } }
E. public class Do implements Doable { public void doSomething(Integer i) { } public void doSomething(String s) { } public void doThat (String s) { } }
Given that these files exist and are accessible:
and given the code fragment:
Which code fragment can be inserted at line n1 to enable the code to print only /company/emp?
A. Stream
B. Stream
C. Stream
D. Stream
What is the result?
A. A compilation error occurs at line 7.
B. 100
C. A compilation error occurs at line 8.
D. A compilation error occurs at line 15.
Given the code fragment:
UnaryOperator
List
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv)) //line n2
.forEach(s -> System.out.print(s + " "));
What is the result?
A. 4000.0
B. 4000
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Given:
class UserException extends Exception { }
class AgeOutOfLimitException extends UserException { }
and the code fragment:
class App {
public void doRegister(String name, int age)
throws UserException, AgeOutOfLimitException {
if (name.length () <= 60) {
throw new UserException ();
} else if (age > 60) {
throw new AgeOutOfLimitException ();
} else {
System.out.println("User is registered.");
}
}
public static void main(String[ ] args) throws UserException {
App t = new App ();
A. doRegister("Mathew", 60); } } What is the result?
B. User is registered.
C. An AgeOutOfLimitException is thrown.
D. A UserException is thrown.
E. A compilation error occurs in the main method.