Java 11 Certification Dumps for 1Z0-815 latest 2020 Set 1

Which line can be uncommented without introducing a compile-time error?
class Foo {
    Object methodA() { return null; }
    String methodB() { return ""; }
}

class Bar extends Foo {
//    int methodA() { return 0; } // Line 1
//    Integer methodA() { return 0; } // Line 2
//    Object methodB() { return null; } // Line 3
//    void methodB() { } // Line 4
//    StringBuilder methodB() { } // Line 5
}


Options are :

  • Line 1
  • Line 2 (Correct)
  • Line 3
  • Line 4
  • Line 5

Answer :Line 2

What is the output of the given code fragment?
Integer[] array = {1, 2};
List<Integer> list = Arrays.asList(array);
list.set(0, 2);
array[1] = 1;
System.out.println(Arrays.toString(array));
System.out.println(list);




Options are :

  • [1, 1]
  • [1, 2]
  • [1, 1]
  • [2, 1] (Correct)
  • [1, 2]
  • [1, 2]

Answer :[2, 1]

What is the program's output?
public class Test {
    public static void main(String[] args) {
        Test test = new Test();
        test.loop(0);
    }
    void loop(int number) {
        for ( ; ; ) {
           if (number < 10) {
                System.out.println(number);
                break;
            }
        }
    }
}


Options are :

  • 0 (Correct)
  • All digits from 0 to 9
  • Nothing
  • It runs into an infinite loop
  • Compilation fails

Answer :0

What is the program's output?
import java.util.List;
package test;
public class MyTest {
    public static void main(String[] args) {
        List<Integer> numbers = List.of();
        for (int number : numbers) {
            System.out.print(number + "===");
        }
    }
}


Options are :

  • ===
  • Nothing
  • An exception is thrown at runtime
  • Compilation fails (Correct)

Answer :Compilation fails

List strings = new ArrayList<>();
strings.addAll(List.of("A", "B"));
System.out.println(strings.remove(0));
System.out.println(strings.remove("A"));
System.out.println(strings.remove("B"));
What is the output of the given code fragment?

Options are :

  • A TRUE TRUE
  • A TRUE FALSE
  • A FALSE TRUE (Correct)
  • TRUE A B
  • TRUE TRUE TRUE
  • TRUE FALSE FALSE

Answer :A FALSE TRUE

Which of the following change enables the given program to compile?
class Foo {
    Foo(String input) /* Position 1 */ {
        if (input == null) {
            return; /* Position 2 */
        } else {
            throw new IOException();
        }
    }
}

public class Test {
    public static void main(String[] args) {
        try {
            new Foo(null /* Position 3 */)
        } catch (Exception /* Position 4 */) e{
            e.printStackTrace();
        }
    }
}


Options are :

  • Insert the throws IOException clause at position 1 (Correct)
  • Remove the return; statement at position 2
  • Replace null at position 3 with a String object
  • Replace type Exception at position 4 with IOException
  • The program has a compile-time error, but none of the above solutions works
  • The program compiles successfully

Answer :Insert the throws IOException clause at position 1

Which of the following changes enables the given code to compile?
package foo;
public abstract class MyFoo {
    abstract void m();
}

And:

package bar;
import foo.MyFoo;
public class MyBar extends MyFoo {
    void m() {
        // A valid body
    }
}


Options are :

  • Declare the method in the MyFoo class as public or protected
  • Declare the method in the MyBar class as public or protected
  • Remove the abstract keyword on the declaration of MyFoo
  • Add the abstract keyword to the declaration of MyBar (Correct)
  • No change is needed as the existing code compiles successfully

Answer :Add the abstract keyword to the declaration of MyBar

What is the output?
class Foo {
    static String foo = init();
    Foo() {
       System.out.println("Super");
    }
    static String init() {
        System.out.println("Init Foo");
        return "Foo";
    }
}
public class Bar extends Foo {
    static String bar = init();
    Bar() {
        System.out.println("Sub");
    }
    static String init() {
        System.out.println("Init Bar");
        return "Bar";
    }
    public static void main(String[] args) {
        new Bar();
    }
}




Options are :

  • Super Sub
  • Init Foo Super Init Bar Sub
  • Init Foo Init Bar Super Sub (Correct)
  • Super Sub Init Foo Init Bar
  • Sub Super
  • Sub Super Init Bar Init Foo

Answer :Init Foo Init Bar Super Sub

What is the program's output?
public class Test {
    public static void main(String[] args) {
        Test test = new Test();
        int sum = test.sumUp(List.of(1, 2, 3, 4, 5));
        System.out.println(sum);
    }
    int sumUp(List<Integer> numbers) {
        int sum = 0;
        myLabel:
        do {
            for (int number : numbers) {
                if (number == 3) break myLabel;
                sum += number;
            }
        } while (sum < 15);
        return sum;
    }
}


Options are :

  • 3 (Correct)
  • 6
  • 10
  • 12
  • 15
  • It runs into an infinite loop

Answer :3

Which access modifiers when added to the s field enable it to be visible outside of the test package?
package test;
class Data {
    /* Insert here */ String s;
}


Options are :

  • public only
  • public or protected
  • protected only
  • no modifier (default)
  • The s field cannot be visible outside of the test package (Correct)

Answer :The s field cannot be visible outside of the test package

Which line of code successfully compiles?
var list = new ArrayList<>(); // Line 1
var i1 = 1, i2 = 2; // Line 2
var string; // Line 3
var object = null; // Line 4
var array = {1, 2}; // Line 5


Options are :

  • Line 1 (Correct)
  • Line 2
  • Line 3
  • Line 4
  • Line 5
  • None of the above

Answer :Line 1

What is the output of the given code fragment?
List list1 = new ArrayList<>(List.of(1, 2, 3, 4, 5));
List list2 = new ArrayList<>(List.of(1, 2, 3));
list1.removeIf(e -> e % 2 == 0);
list1.retainAll(list2);
System.out.println(list1);


Options are :

  • []
  • [1, 2, 3]
  • [1, 2, 3, 4, 5]
  • [1, 3] (Correct)
  • [2, 4]
  • [4, 5]

Answer :[1, 3]

Which two options specify the module to compile when using the javac command?


Options are :

  • -m (Correct)
  • -module
  • --module (Correct)
  • --module-name
  • --compiled-module

Answer :-m --module

What is correct about the given code?
interface Foo {
    abstract void m(); // Line 1
}
class Bar implements Foo {
    @Override // Line 2
    void m() { } // Line 3
}


Options are :

  • It doesn't compile because the abstract keyword isn't allowed on line 1
  • It doesn't compile because the @Override annotation on line 2 is invalid
  • It doesn't compile because a modifier is missing on line 3 (Correct)
  • It compiles successfully

Answer :It doesn't compile because a modifier is missing on line 3

What is the program's output?
public class Test {
    public static void main(String[] args) {
        int[] array = {0, 2, 4};
        int index;
        int element = array[index = 1]++;
        System.out.println(index + ": " + array[index] + " -> " + element);
    }
}


Options are :

  • 0: 0 -> 1
  • 0: 1 -> 0
  • 0: 1 -> 1
  • 1: 2 -> 3
  • 1: 3 -> 2 (Correct)
  • 1: 3 -> 3

Answer :1: 3 -> 2

Which statement is correct about the given method?
String select(int number) {
    String output;
    switch (number) {
        case 0:
        default:
        case 1:
            output = "positive";
    }
    return output;
}


Options are :

  • It fails to compile as the output local variable might not be initialized
  • It fails to compile as the default label is at an inappropriate position
  • If we call select(0), it'll return null
  • If we called select(2), it'll return "positive" (Correct)
  • None of the above

Answer :If we called select(2), it'll return "positive"

Given a class with name my.test.Main:
package my.test;
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello");
    }
}

This class is included in a module called my.test.Main, which is wrapped in a JAR file called mytest.jar. Which of the following command executes the given program when the JAR file is put in the working directory?


Options are :

  • java -classpath mytest.jar my.test/my.test.Main
  • java -p . -m my.test/my.test.Main (Correct)
  • java --module-path . -module my.test/my.test.Main
  • java -p mytest.jar/my.test/my.test.Main
  • java -p mytest.jar -m my.test/my.test.Main.main
  • java -p mytest.jar -m my.test -c my.test.Main

Answer :java -p . -m my.test/my.test.Main

What is the output of the given program?
interface MyFoo {
    int number = 0;
    void calculate(int arg);
}
class MyBar implements MyFoo {
    int number = 10;
    public void calculate(int arg) {
        number += arg;
    }
}
class Test {
    public static void main(String[] args) {
        MyFoo foo = new MyBar();
        foo.calculate(20);
        System.out.println(foo.number);
    }
}


Options are :

  • 0 (Correct)
  • 10
  • 20
  • 30
  • Compilation fails

Answer :0

What is the given program's output?
public class Test {
    static int getNumber() throws Exception {
        throw new Exception("test");
    }
    public static void main(String[] args) {
       int i = 0;
        try {
            int j = 1 / i * getNumber();
        } catch (Exception e) {
            System.out.println(j + ": " + e.getMessage());
        }
    }
}


Options are :

  • 0: / by zero
  • 0: test
  • 1: / by zero
  • 1: test
  • NaN: / by zero
  • Compilation fails (Correct)

Answer :Compilation fails

What happens when compiling and executing the given program?
class Foo {
    public void m() {
        System.out.println("Foo");
    }
}
class Bar extends Foo {
    public void m(String arg) throws Exception { // Line 1
        System.out.println(arg);
    }
}
public class Test {
    public static void main(String[] args) {
        Foo foo = new Bar();
        foo.m("Bar"); // Line 2
        Bar bar = (Bar) foo;
        bar.m(); // Line 3
    }
}

Options are :

  • It prints "Bar" twice
  • It prints "Bar", then "Foo"
  • It throws a ClassCastException
  • Compilation fails on line 1
  • Compilation fails on line 2 (Correct)
  • Compilation fails on line 3

Answer :Compilation fails on line 2

Which two of the following are valid entry methods of a program?


Options are :

  • public static void main(String... arguments) { // a valid body } (Correct)
  • public static void main(Collection args) { // a valid body }
  • public static void Main(String[] arguments) { // a valid body }
  • public static String main(String[] arguments) { // a valid body }
  • static public void main(String[] strings) { // a valid body } (Correct)
  • public void main(String[] args) { // a valid body }

Answer :public static void main(String... arguments) { // a valid body } static public void main(String[] strings) { // a valid body }

Which of the following is correct about the break statement on line 1?
int select(List<Integer> list) {
    for (int i : list) {
        switch (i) {
            case 1:
                return i;
                break; // Line 1
            default:
                System.out.println("default");
        }
    }
    return 0;
}


Options are :

  • It prevents the switch block from falling through
  • It terminates the for-each construct when the second element in the list is processed
  • It terminates the for-each construct when a list element with value 1 is processed
  • It makes the given method fail to compile (Correct)
  • It's redundant and removing it doesn't make any difference

Answer :It makes the given method fail to compile

How many objects are created when the given code fragment is executed?
String s1 = "Hello";
String s2 = " ";
String s3 = "World!";
String s = s1 + s2 + s3;


Options are :

  • 1
  • 2
  • 3
  • 4
  • 5 (Correct)
  • 6

Answer :5

What is the program's output?
class Foo {
    protected static int myField = 2019;
    protected static Object myMethod() {
        return myField;
    }
}
public class Bar extends Foo {
    public String myField = "Bar";
    public static String myMethod() {
        return new Bar().myField;
    }
    public static void main(String[] args) {
        Foo foo = new Bar();
        System.out.println(foo.myField);
        System.out.println(foo.myMethod());
    }
}


Options are :

  • 2019 2019 (Correct)
  • 2019 Bar
  • Bar 2019
  • Bar Bar
  • Compilation fails

Answer :2019 2019

What is the given code's output?
int a = 1, b = 2, c = 3, d = 4;
a = b = c;
b = -d;
c *= c;
d %= a;
System.out.println(a + " " + b + " " + c + " " + d);


Options are :

  • 0 -2 9 0
  • 1 -1 1 1
  • 1 -4 3 3
  • 3 -4 9 1 (Correct)
  • An ArithmeticException is thrown
  • Compilation fails

Answer :3 -4 9 1

Which of the following changes doesn't make the given code able to compile?
interface Foo {
    void methodA();
}
abstract class Bar /* Position 1 */ {
    /* Position 2 */
    public abstract void methodB();
}
public class FooBar /* Position 3 */ {
    @Override /* Position 4 */
    public void methodA() {
        // a valid body
    }
    @Override /* Position 5 */    
public void methodB() {
        // a valid body
    }
}


Options are :

  • Insert implements Foo at position 1 and extends Bar at position 3
  • Insert extends Bar implements Foo at position 3
  • Insert extends Bar at position 3 and remove @Override at position 4
  • Insert public void methodA() {} at position 2 and implements Foo at position 3 (Correct)
  • Insert implements Foo at position 3 and remove @Override at position 5

Answer :Insert public void methodA() {} at position 2 and implements Foo at position 3

What is the output of the given code?
try {
    throw new IOException();
} catch (RuntimeException e1) { // Line 1
    System.out.println("RuntimeException");
} catch (Exception e2) { // Line 2
    System.out.println("Exception");
} catch (IOException e3) { // Line 3
    System.out.println("IOException");
}


Options are :

  • RuntimeException
  • Exception
  • IOException
  • An exception is thrown up the call stack
  • Compilation fails on line 1
  • Compilation fails on line 3 (Correct)

Answer :Compilation fails on line 3

Which statement when placed on line 1 makes the given code print letter "f"?
String[][] matrix = {?{"a", "b", "c"}, {"d", "e", "f"}};
// Line 1
System.out.println(element);


Options are :

  • String element = matrix[1, 2];
  • String element = matrix[2][1];
  • String element = matrix[2][3];
  • String element = matrix(2)(3);
  • String element = matrix(2, 3);
  • None of the above (Correct)

Answer :None of the above

What is the program's output?
String text = "This is it";
int index = text.indexOf("is");
text = text.substring(index + 3);
text.substring(1, 3);
System.out.println(text);


Options are :

  • is
  • it
  • is it (Correct)
  • This is it
  • An IndexOutOfBoundsException is thrown

Answer :is it

What is the given code fragment's output?
int x = 1, y = 2, z = 3;
x -= y += z;
System.out.println(x + " " + y);


Options are :

  • -4 5 (Correct)
  • -1 2
  • 1 4
  • 4 5

Answer :-4 5

Which line causes a compilation error?
abstract class Foo {
    Foo(String arg) { // Line 1
        System.out.println(arg);
    }
}
public class Bar extends Foo {
    Bar(String arg) { // Line 2
        super(arg); // Line 3
    }
    public static void main(String[] args) {
        Foo foo = new Foo("test"); // Line 4
        Bar bar = new Bar("test"); // Line 5
    }
}


Options are :

  • Line 1
  • Line 2
  • Line 3
  • Line 4 (Correct)
  • Line 5
  • The compilation succeeds

Answer :Line 4

Which lines of code cause compile-time errors?
class Foo {
    CharSequence sequence;
    Foo(CharSequence sequence) {
        this.sequence = sequence;
    }
}
public class Test {
    public static void main(String[] args) {
        Foo foo1 = new Foo(); // Line 1
        Foo foo2 = new Foo("string"); // Line 2
        Foo foo3 = new Foo(new StringBuilder("builder")); // Line 3
    }
}


Options are :

  • Line 1 only (Correct)
  • Line 2 only
  • Line 3 only
  • Line 2 and line 3
  • Compilation succeeds

Answer :Line 1 only

What is the program's output?
StringBuilder builder = new StringBuilder("ABCD");
builder.replace(1, 3, "C").insert(4, "Q");
System.out.println(builder);


Options are :

  • ABCD
  • ABQ
  • ACQ
  • ACDQ
  • ACD Q (there's a space between D and Q)
  • An exception is thrown (Correct)

Answer :An exception is thrown

Which two of the following aren't provided in the JDK?


Options are :

  • Version control systems (Correct)
  • Integrated development environments (Correct)
  • Interactive shells
  • Security tools
  • Deployment tools

Answer :Version control systems Integrated development environments

Which lines of code cause compilation failure?
interface Foo {
    int fieldA = 0;
    int fieldB = 0;
    void methodA();
    static void methodB() {
        // a valid body
    }
}
interface Bar extends Foo {
    int fieldA = 1; // Line 1
    int fieldB = Foo.fieldB; // Line 2
    static void methodA() { // Line 3
        // a valid body
   }
    void methodB(); // Line 4
}


Options are :

  • Line 1 only
  • Line 1 and line 2
  • Line 1, line 2, line 3 and line 4
  • Line 2 only
  • Line 3 only (Correct)
  • Line 3 and line 4

Answer :Line 3 only

What happens when compiling and executing the given program?
Given the bar module:
module bar {
    requires foo;
    exports bar;
}
With a class:
package bar;
public class MyBar { }
And here's the foo module:
module foo {
    requires bar;
}
With another class:
package foo;
import bar.MyBar;
public class MyFoo {
   public static void main(String[] args) {
        new MyBar();
    }
}


Options are :

  • The foo module is loaded before the bar module
  • The foo module is loaded after the bar module
  • The application compiles, but fails to start
  • The application fails to compile (Correct)

Answer :The application fails to compile

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions