1Z0-809 Premium Bundle

1Z0-809 Premium Bundle

Java SE 8 Programmer II Certification Exam

4.5 
(4845 ratings)
0 QuestionsPractice Tests
0 PDFPrint version
November 5, 2024Last update

Oracle 1Z0-809 Free Practice Questions

Q1. Which three statements are benefits of encapsulation? 

A. Allows a class implementation to change without changing t he clients 

B. Protects confidential data from leaking out of the objects 

C. Prevents code from causing exceptions 

D. Enables the class implementation to protect its invariants 

E. Permits classes to be combined into the same package 

F. Enables multiple instances of the same class to be created safely 

Answer: A,B,D 

Q2. Given the code fragment: 

BiFunction<Integer, Double, Integer> val = (t1, t2) -> t1 + t2;//line n1 

System.out.println(val.apply(10, 10.5)); 

What is the result? 

A. 20 

B. 20.5 

C. A compilation error occurs at line n1. 

D. A compilation error occurs at line n2. 

Answer:

Q3. Given: 

Which two classes use the shape class correctly? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

E. Option E 

F. Option F 

Answer: B,E 

Explanation: When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class (E). However, if it does not, then the subclass must also be declared abstract (B). Note: An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. 

Q4. Given: 

class Student { 

String course, name, city; 

public Student (String name, String course, String city) { 

this.course = course; this.name = name; this.city = city; 

public String toString() { 

return course + “:” + name + “:” + city; 

and the code fragment: 

List<Student> stds = Arrays.asList( 

new Student (“Jessy”, “Java ME”, “Chicago”), 

new Student (“Helen”, “Java EE”, “Houston”), 

new Student (“Mark”, “Java ME”, “Chicago”)); 

stds.stream() 

.collect(Collectors.groupingBy(Student::getCourse)) 

.forEach(src, res) -> System.out.println(scr)); 

What is the result? 

A. [Java EE: Helen:Houston] 

[Java ME: Jessy:Chicago, Java ME: Mark:Chicago] 

B. Java EE 

Java ME 

C. [Java ME: Jessy:Chicago, Java ME: Mark:Chicago] 

[Java EE: Helen:Houston] 

D. A compilation error occurs. 

Answer:

Q5. Given: What is the result? 

A. 100 210 

B. Compilation fails due to an error in line n1 

C. Compilation fails due to an error at line n2 

D. Compilation fails due to an error at line n3 

Answer:

Q6. 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. 

Answer:

Q7. Given: 

class FuelNotAvailException extends Exception { } 

class Vehicle { 

void ride() throws FuelNotAvailException {//line n1 

System.out.println(“Happy Journey!”); 

class SolarVehicle extends Vehicle { 

public void ride () throws Exception {//line n2 

super ride (); 

and the code fragment: 

public static void main (String[] args) throws FuelNotAvailException, Exception { 

Vehicle v = new SolarVehicle (); 

v.ride(); 

Which modification enables the code fragment to print Happy Journey!? 

A. Replace line n1 with public void ride() throws FuelNotAvailException { 

B. Replace line n1 with protected void ride() throws Exception { 

C. Replace line n2 with void ride() throws Exception { 

D. Replace line n2 with private void ride() throws FuelNotAvailException { 

Answer:

Q8. Given the code fragment: 

LocalDate valentinesDay =LocalDate.of(2015, Month.FEBRUARY, 14); 

LocalDate nextYear = valentinesDay.plusYears(1); 

nextYear.plusDays(15); //line n1 

System.out.println(nextYear); 

What is the result? 

A. 2021-02-14 

B. A DateTimeException is thrown. 

C. 2021-02-29 

D. A compilation error occurs at line n1. 

Answer:

Q9. Given: 

class Bird { 

public void fly () { System.out.print(“Can fly”); } 

class Penguin extends Bird { 

public void fly () { System.out.print(“Cannot fly”); } 

and the code fragment: 

class Birdie { 

public static void main (String [ ] args) { 

fly( ( ) -> new Bird ( )); 

fly (Penguin : : new); 

/* line n1 */ 

Which code fragment, when inserted at line n1, enables the Birdie class to compile? 

A. static void fly (Consumer<Bird> bird) { 

bird :: fly (); } 

B. static void fly (Consumer<? extends Bird> bird) { 

bird.accept( ) fly (); 

C. static void fly (Supplier<Bird> bird) { 

bird.get( ) fly (); 

D. static void fly (Supplier<? extends Bird> bird) { 

LOST 

Answer:

Explanation: NOTE: Very confusing question. There is no logic in the options. 

Q10. 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. 

Answer:

Q11. Given the code fragment: 

List<String> nL = Arrays.asList(“Jim”, “John”, “Jeff”); 

Function<String, String> funVal = s -> “Hello : “.contact(s); 

nL.Stream() 

.map(funVal) 

.peek(System.out::print); 

What is the result? 

A. Hello : Jim Hello : John Hello : Jeff 

B. Jim John Jeff 

C. The program prints nothing. 

D. A compilation error occurs. 

Answer:

Q12. 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. 

Answer:

Q13. Given the code fragment: 

List<String> colors = Arrays.asList(“red”, “green”, “yellow”); 

Predicate<String> test = n - > { 

System.out.println(“Searching…”); 

return n.contains(“red”); 

}; 

colors.stream() 

.filter(c -> c.length() > 3) 

.allMatch(test); 

What is the result? 

A. Searching… 

B. Searching… Searching… 

C. Searching… Searching… Searching… 

D. A compilation error occurs. 

Answer:

Q14. Which two are Java Exception classes? 

A. SercurityException 

B. DuplicatePathException 

C. IllegalArgumentException 

D. TooManyArgumentsException 

Answer: A,C 

Q15. Given: 

A. Ym Xm2 

B. Ym Xm1 

C. Compilation fails 

D. A ClassCastException is thrown at runtime 

Answer:

START 1Z0-809 EXAM