1z0-809 Practice Test Questions

128 Questions


Given the code fragments:

What is the result?


A.

Super
Sub
Sub


B.

Contract
Contract
Super


C.

Compilation fails at line n1


D.

Compilation fails at line n2





D.
  

Compilation fails at line n2



Given the content of /resourses/Message.properties:
welcome1=”Good day!”
and given the code fragment:
Properties prop = new Properties ();
FileInputStream fis = new FileInputStream (“/resources/Message.properties”);
prop.load(fis);
System.out.println(prop.getProperty(“welcome1”));
System.out.println(prop.getProperty(“welcome2”, “Test”));//line n1
System.out.println(prop.getProperty(“welcome3”));
What is the result?


A.

Good day!
Test
followed by an Exception stack trace


B.

Good day!
followed by an Exception stack trace


C.

Good day!
Test
null


D.

A compilation error occurs at line n1.





D.
  

A compilation error occurs at line n1.



Given:
Class A { }
Class B { }
Interface X { }
Interface Y { }
Which two definitions of class C are valid?


A.

Class C extends A implements X { }


B.

Class C implements Y extends B { }


C.

Class C extends A, B { }


D.

Class C implements X, Y extends B { }


E.

Class C extends B implements X, Y { }





A.
  

Class C extends A implements X { }



E.
  

Class C extends B implements X, Y { }



extends is for extending a class.
implements is for implementing an interface.
Java allows for a class to implement many interfaces.

Which statement is true about java.util.stream.Stream?


A.

A stream cannot be consumed more than once.


B.

The execution mode of streams can be changed during processing.


C.

Streams are intended to modify the source data.


D.

A parallel stream is always faster than an equivalent sequential stream





B.
  

The execution mode of streams can be changed during processing.



Given:
interface Rideable {Car getCar (String name); }
class Car {
private String name;
public Car (String name) {
this.name = name;
}
}
Which code fragment creates an instance of Car?


A.

Car auto = Car (“MyCar”): : new;


B.

Car auto = Car : : new;
Car vehicle = auto : : getCar(“MyCar”);


C.

Rideable rider = Car : : new;
Car vehicle = rider.getCar(“MyCar”);


D.

Car vehicle = Rideable : : new : : getCar(“MyCar”);





C.
  

Rideable rider = Car : : new;
Car vehicle = rider.getCar(“MyCar”);



Given the code fragments:
class Caller implements Callable<String> {
String str;
public Caller (String s) {this.str=s;}
public String call()throws Exception { return str.concat (“Caller”);}
}
class Runner implements Runnable {
String str;
public Runner (String s) {this.str=s;}
public void run () { System.out.println (str.concat (“Runner”));}
}
and
public static void main (String[] args) InterruptedException, ExecutionException {
ExecutorService es = Executors.newFixedThreadPool(2);
Future f1 = es.submit (new Caller (“Call”));
Future f2 = es.submit (new Runner (“Run”));
String str1 = (String) f1.get();
String str2 = (String) f2.get();//line n1
System.out.println(str1+ “:” + str2);
}
What is the result?


A.

The program prints:
Run Runner
Call Caller : null
And the program does not terminate.


B.

The program terminates after printing:
Run Runner
Call Caller : Run


C.

A compilation error occurs at line n1.


D.

An Execution is thrown at run time.





A.
  

The program prints:
Run Runner
Call Caller : null
And the program does not terminate.



Given:
class Book {
int id;
String name;
public Book (int id, String name) {
this.id = id;
this.name = name;
}
public boolean equals (Object obj) { //line n1
boolean output = false;
Book b = (Book) obj;
if (this.name.equals(b name))}
output = true;
}
return output;
}
}
and the code fragment:
Book b1 = new Book (101, “Java Programing”);
Book b2 = new Book (102, “Java Programing”);
System.out.println (b1.equals(b2)); //line n2
Which statement is true?


A.

The program prints true.


B.

The program prints false.


C.

A compilation error occurs. To ensure successful compilation, replace line n1 with:
boolean equals (Book obj) {


D.

A compilation error occurs. To ensure successful compilation, replace line n2 with:
System.out.println (b1.equals((Object) b2));





C.
  

A compilation error occurs. To ensure successful compilation, replace line n1 with:
boolean equals (Book obj) {



Given the definition of the Vehicle class:
Class Vehhicle {
int distance;//line n1
Vehicle (int x) {
this distance = x;
}
public void increSpeed(int time) {//line n2
int timeTravel = time;//line n3
class Car {
int value = 0;
public void speed () {
value = distance /timeTravel;
System.out.println (“Velocity with new speed”+value+”kmph”);
}
}
new Car().speed();
}
}
and this code fragment:
Vehicle v = new Vehicle (100);
v.increSpeed(60);
What is the result?


A.

Velocity with new speed


B.

A compilation error occurs at line n1.


C.

A compilation error occurs at line n2.

 


D.

A compilation error occurs at line n3.





A.
  

Velocity with new speed



Given:



A.

X XX


B.

X Y X


C.

Y Y X


D.

Y YY





D.
  

Y YY



Given the code fragment:
public static void main (String [ ] args) throws IOException {
BufferedReader br = new BufferedReader (new InputStremReader (System.in));
System.out.print (“Enter GDP: “);
//line 1
}
Which code fragment, when inserted at line 1, enables the code to read the GDP from the
user?


A.

int GDP = Integer.parseInt (br.readline());


B.

int GDP = br.read();


C.

int GDP = br.nextInt();


D.

int GDP = Integer.parseInt (br.next());





C.
  

int GDP = br.nextInt();



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 () < 6) {
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 ();
t.doRegister(“Mathew”, 60);
}
}
What is the result?


A.

User is registered.


B.

An AgeOutOfLimitException is thrown.


C.

A UserException is thrown.


D.

A compilation error occurs in the main method.





A.
  

User is registered.



Which statement is true about java.time.Duration?


A.

It tracks time zones.


B.

It preserves daylight saving time.


C.

It defines time-based values.


D.

It defines date-based values.





C.
  

It defines time-based values.



Reference: http://tutorials.jenkov.com/java-date-time/duration.html#accessing-the-time-ofa-
duration


Page 2 out of 11 Pages
Previous