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

What is the program's output?
interface Foo {
    String text = "Foo";
    static void print() {
        System.out.println(text);
    }
}
public class Bar implements Foo {
    String text = "Bar";
    public static void main(String[] args) {
        Foo foo = new Bar();
        foo.print();
        System.out.println(foo.text);
    }
}


Options are :

  • Foo Foo
  • Foo Bar
  • Bar Foo
  • Bar Bar
  • Compilation fails

Answer :Compilation fails

What is the program's output?
public class Test {
    public static void main(String[] args) {
        Test test = new Test();
        test.compare('A');
       test.compare('b');
    }
    void compare(char character) {
        if (character = 'A') { // Line 1
            System.out.println("character is in uppercase");
        } else if (character > 'a') { // Line 2
            System.out.println("character is in lowercase");
        } else {
            System.out.println("not sure");
        }
    }
}


Options are :

  • character is in uppercase character is in lowercase
  • character is in uppercase not sure
  • character is in lowercase not sure
  • Compilation fails on line 1
  • Compilation fails on line 2

Answer :Compilation fails on line 1

What is the program's output?
String text1 = "Hello";
String text2 = "Hello World";
String text3 = "hello world";
int text1VsText2 = text1.compareTo(text2);
int text2VsText3 = text2.compareTo(text3);
System.out.println(text1VsText2 + " " + text2VsText3);


Options are :

  • -2
  • 1 1
  • -6 0
  • 6 0
  • -38
  • 6 32

Answer :-38

Which array declaration is valid?
int[][] matrix1 = new int[][];
int[][] matrix2 = new int[2][];
int[][] matrix3 = new int[][3];
int[2][3] matrix4 = new int[2][3];


Options are :

  • matrix1
  • matrix2
  • matrix3
  • matrix4
  • None

Answer :matrix2

What is the program's output?
class Foo {
    String name = "Foo";
    void print() {
        this.print(new Bar().name); // Line 1
    }
    void print(String argument) {
        System.out.println(argument);
    }
}
class Bar extends Foo {
    String name = "Bar";
    void print() {
        this.print(super.name); // Line 2
    }
}
public class Test {
    public static void main(String[] args) {
        Foo foo = new Bar();
        foo.print();
    }
}


Options are :

  • Foo
  • Bar
  • Compilation fails one line 1
  • Compilation fails on line 2

Answer :Foo

What is the program's output?
public class Test {
    public static void main(String[] args) {
        try {
            Test test = new Test();
            if (test.isPositive(1))
                throw new RuntimeException();
            System.out.println("try");
        } catch (Exception e) {
            System.out.println("catch");
        } finally {
            System.out.println("finally");
        }
    }
    boolean isPositive(int input) {
        return input > 0;
    }
}


Options are :

  • try catch finally
  • try finally catch
  • catch
  • catch finally
  • finally
  • finally catch

Answer :catch finally

What is the program's output?
StringBuilder builder = new StringBuilder("ABC");
builder.reverse().setCharAt(0, "D");
System.out.println(builder);


Options are :

  • ABC
  • CBD
  • DBA
  • DCBA
  • Compilation fails

Answer :Compilation fails

Which lines of code cause compilation failure?
interface Foo {
    void methodA();
    void methodB();
}
interface Bar extends Foo {
    @Override // Line 1
    void methodA();
    @Override // Line 2
    void methodC();
}
class Baz implements Bar {
    @Override // Line 3
    public void methodA() {
        // a valid body
    }
    @Override // Line 4
    public void methodB() {
        // a valid body
    }
   @Override // Line 5
    public void methodC() {
       // a valid body
    }
}


Options are :

  • Line 1 only
  • Line 1 and line 2
  • Line 1 and line 3
  • Line 2 only
  • Line 2 and line 3
  • Line 2 and line 4

Answer :Line 2 only

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) {
       while (++number < 5) {
            number++;
            System.out.print(number + " ");
        }
    }
}


Options are :

  • 1 2 3 4
  • 1 3 2005
  • 2 3 4 5
  • 2 4
  • 2 4 2006

Answer :2 4

Which command lists all the modules required by a target module?


Options are :

  • java --list-modules
  • java --show-modules
  • javac --show-modules
  • jmod --list
  • jdeps --list-deps

Answer :jdeps --list-deps

Which of the following statement is correct?
class Foo {
    List getList(List input) { return new ArrayList(input)
} // Method A
}
public class Bar extends Foo {
    List getList() { return new ArrayList();} // Method B
    Collection getList(Collection input) {return new ArrayList();} // Method C
    ArrayList getList(ArrayList input) { return new ArrayList();} // Method D
    Collection getList(List input) {return new ArrayList();} // Method E
}


Options are :

  • Method B overloads, method D overrides, while methods C and E hide method A
  • Method B overloads method A, while methods C, D and E overrides it
  • Methods B and C overload method A, while methods D and E overrides it
  • Methods B, C and D overload method A while method E overrides it
  • Methods B and D override method A while methods C and E overload it
  • None of the methods B, C, D and E overrides method A

Answer :None of the methods B, C, D and E overrides method A

Given the Foo.java file:

package test;
public class Foo {
    String text;
   public Foo(String text) {
       this.text = text;
    }
    public String toString() {
        return text;
   }
}

And Bar.java file:

package test;
import java.util.*;
public class Bar {
    public static void main(String[] args) {
        Foo foo1 = new Foo("Hi");
        Foo foo2 = new Foo("Hey");
        Foo[] foos = {foo1, foo2};
        System.out.println(Arrays.toString(foos));
    }
}
Which of the following statements is correct about the given code?


Options are :

  • All types in the java.util package are loaded when the program is executed
  • The package containing the String and System classes must be explicitly imported into the Foo.java and Bar.java files, respectively
  • The Bar.java file must import the Foo class
  • None of the above

Answer :None of the above

String string = String.format("Welcome to [placeholder] century", "st", 21);
System.out.println(string);

Which string when replacing [placeholder] produces "Welcome to 21st century" on the console?


Options are :

  • %$d%$s
  • %1$d%0$s
  • %2$s%1$s
  • It's possible, but none of the above options are correct
  • It's impossible as format arguments "st" and 21 are in incorrect order
  • It's impossible as the format method accepts only one format argument

Answer :%2$s%1$s

What is the output of the given code?
List<String> list = List.of(); // Line 1
for (Object element : list) { // Line 2
    System.out.println(element);
}


Options are :

  • null
  • Nothing
  • A NullPointerException is thrown
  • Compilation fails on line 1
  • Compilation fails on line 2

Answer :Nothing

What is the program's output?
interface Foo {
    String myField = "Foo";
    void myMethod();
}
interface Bar {
    String myField = "Bar";
    void myMethod();
}
public class Test implements Foo, Bar { // Line 1
    @Override // Line 2
    public void myMethod() {
        System.out.println(myField); // Line 3
    }
    public static void main(String[] args) {
        Test test = new Test();
        test.myMethod(); // Line 4
    }
}


Options are :

  • Foo
  • Bar
  • Compilation fails on line 1
  • Compilation fails on line 2
  • Compilation fails on line 3
  • Compilation fails on line 4

Answer :Compilation fails on line 3

What is the program output?
public class Test {
    int add(int... addends) {
        System.out.println("Variable arity");
        int sum = 0;
        for (int addend : addends) {
            sum += addend;
        }
        return sum;
    }
    Number add(Number addend1, Number addend2) {
        System.out.println("Object arguments");
        return (int) addend1 + (int) addend2;
    }
    long add(long addend1, long addend2) {
        System.out.println("Primitive arguments");
        return addend1 + addend2;
    }
    public static void main(String[] args) {
        Test test = new Test();
        Number sum = test.add(Integer.valueOf("1"), Integer.valueOf("2"));
    }
}


Options are :

  • Variable arity
  • Object arguments
  • Primitive arguments
  • Compilation fails

Answer :Object arguments

What is the output?
String text = "abcd";
text.substring(1, 3);
text.subSequence(2, 0);
System.out.println(text);


Options are :

  • abcd
  • ad
  • cd
  • Nothing
  • An exception is thrown
  • Compilation fails

Answer :An exception is thrown

What is the output when executing the given code?
String[] array1 = {"a", "b", "c"};
String[] array2 = {"a", "b", "c"};
int result = Arrays.mismatch(array1, 1, 3, array2, 2, 3);
System.out.println(result);


Options are :

  • -1
  • 0
  • 1
  • 2
  • An ArrayIndexOutOfBoundsException is thrown

Answer :0

What is the given program's output?
class Foo {
    String string = "Foo";
    static void print() {
        System.out.println(new Foo().string);
    }
}
class Bar extends Foo {
    static String string = "Bar";
    static void print() {
        System.out.println(string);
    }
    public static void main(String[] args) {
        Foo foo = new Bar();
        foo.print();
        Bar bar = new Bar();
        bar.print();
    }
}


Options are :

  • Foo Foo
  • Foo Bar
  • Bar Foo
  • Bar Bar
  • Compilation fails

Answer :Foo Bar

Which two statements correctly create a LocalDate instance representing 01 January 2019?


Options are :

  • LocalDate date = new LocalDate(2019, 1, 1);
  • LocalDate date = LocalDate.parse("2019-1-1");
  • LocalDate date = LocalDate.of(2019, 1, 1);
  • LocalDate date = LocalDate.of(2019, "JANUARY", 1);
  • LocalDate date = LocalDate.ofYearDay(2019, 1);

Answer :LocalDate date = LocalDate.of(2019, 1, 1); LocalDate date = LocalDate.ofYearDay(2019, 1);

Which two of the following are main goals of the Java module system?


Options are :

  • Reliable configuration
  • Strong encapsulation
  • Scalable Java platform
  • Greater platform integrity
  • Improved performance

Answer :Reliable configuration Strong encapsulation

What is the output?
List list = new ArrayList<>(1);
list.add(2);
list.add(3);
System.out.println(list);


Options are :

  • [1, 2, 3]
  • [1, 3, 2]
  • [2, 3]
  • [2, 3, 1]
  • [3, 2]
  • [3, 2, 1]

Answer :[2, 3]

What is the output of the given code fragment?
int i, j;
for (i = 3, j = 1; i + j < 7; i + 1, j + 2) {
    if (i == j) {
        break;
    }
}
System.out.println(i + " " + j);


Options are :

  • 3 1
  • 4 3
  • 5 5
  • It runs into an infinite loop
  • Compilation fails

Answer :Compilation fails

Given the synopsis of the javac command:
javac [options] [source-files]
What can be specified as the source-files value?


Options are :

  • One or more source code files
  • One or more bytecode class files
  • Any number of source code files and bytecode class files
  • A single source code file or a directory containing source code files
  • Any number of source code files and directories containing source code files

Answer :Any number of source code files and bytecode class files

Which three changes when made independently allow the given code to compile?
interface Foo {
    void x();
}
abstract class Bar /* Position 1 */ {
   /* Position 2 */
    public void x() { }
    public abstract void y(); /* Position 3 */
}
/* Position 4 */ class FooBar extends Bar implements Foo {
    /* Position 5 */
}


Options are :

  • Add implements Foo at position 1 and abstract at position 4
  • Add @Override at position 2 and replace the method at position 3 with public void y() { }
  • Remove method y at position 3
  • Add abstract at position 4
  • Add void y() { } at position 5

Answer :Add implements Foo at position 1 and abstract at position 4 Remove method y at position 3 Add abstract at position 4

Which of the following describes the encapsulation concept?


Options are :

  • A process of wrapping code and data together into a single unit
  • A process of showing only relevant data and hide the implementation details from users
  • A concept by which a single action can be performed in different ways
  • A process where one class acquires fields and methods and fields of another
  • None of the above

Answer :A process of wrapping code and data together into a single unit

It's known that 14 June 2019 is Friday. What is the given code fragment's output?
LocalDate localDate = LocalDate.of(2019, 6, 14)
        .with(DayOfWeek.TUESDAY);
localDate = localDate.minusDays(30)
        .plus(1, ChronoUnit.MONTHS);
System.out.println(localDate.getDayOfWeek());


Options are :

  • MONDAY
  • TUESDAY
  • WEDNESDAY
  • THURSDAY
  • FRIDAY
  • SATURDAY

Answer :WEDNESDAY

What is the output of the given code?
String[] array1 = {"hello", "world"};
String[] array2 = Arrays.copyOf(array1, 1);
System.out.println(array2[1]);


Options are :

  • null
  • world
  • A NullPointerException is thrown
  • An ArrayIndexOutOfBoundsException is thrown
  • Compilation fails

Answer :An ArrayIndexOutOfBoundsException is thrown

What is the program's output?
class Foo {
    @Override
    public boolean equals(Object obj) {
        return true;
    }
    @Override
    public int hashCode() {
        return 0;
    }
}
public class Test {
    public static void main(String[] args) {
        List list = new ArrayList<>();
        list.add(new Foo());
        list.add(new Foo());
        list.remove(new Foo());
        System.out.println(list.contains(new Foo()));
        list.remove(new Foo());
        System.out.println(list.isEmpty());
    }
}


Options are :

  • TRUE TRUE
  • TRUE FALSE
  • FALSE TRUE
  • FALSE FALSE
  • A NullPointerException is thrown
  • An IndexOutOfBoundsException is thrown

Answer :TRUE TRUE

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));
        System.out.println(sum);
    }
    int sumUp(List<Integer> list) {
        int sum = 0;
        myLabel:
        do {
            for (int number : list) {
                sum += number;
                if (number == 3) break;
            }
        } while (sum < 10);
        return sum;
    }
}


Options are :

  • 0
  • 3
  • 6
  • 10
  • 12
  • It runs into an infinite loop

Answer :12

What is the program's output?
public class Person {
    String name;
    static int age;
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public static void main(String[] args) {
        Person person1 = new Person("John", 20);
        Person person2 = new Person("Jane", 30);
        System.out.println(person1.name + " " + person1.age);
        System.out.println(person2.name + " " + person2.age);
    }
}


Options are :

  • John 20 Jane 20
  • John 20 Jane 30
  • John 30 Jane 20
  • John 30 Jane 30
  • Compilation fails

Answer :John 30 Jane 30

What is the given program's output?
public class Test {
    static public void main(String[] args) {
        var list = new ArrayList<>(); // Line 1
        list.add("a"); // Line 2
        list.add(1); // Line 3
        for (var element : list) { // Line 4
            System.out.print(element + " ");
        }
        for (var i = 0; i < list.size(); i++) { // Line 5
            System.out.print(list.get(i) + " ");
        }
    }
}


Options are :

  • a 1 a 1
  • Compilation fails on line 1
  • Compilation fails on line 2
  • Compilation fails on line 3
  • Compilation fails on line 4
  • Compilation fails on line 5

Answer :a 1 a 1

Which of the following can be a valid directive in a module declaration?


Options are :

  • exports foo, boo;
  • exports foo to boo;
  • requires bar, baz;
  • requires bar from baz;
  • exports foo requires bar;

Answer :exports foo to boo;

What is the program's output?
public class Test {
    void methodA() throws IOException {
        throw new FileNotFoundException(); // Line 1
    }
    void methodB() throws FileNotFoundException {
       methodA(); // Line 2
    }
    public static void main(String[] args) {
        Test test = new Test();
        try {
            test.methodA(); // Line 3
        } catch (Throwable t) {
            System.out.println("Throwable");
        }
    }
}


Options are :

  • Throwable
  • An exception is thrown up the call stack
  • Compilation fails on line 1
  • Compilation fails on line 2
  • Compilation fails on line 3

Answer :Compilation fails on line 2

class Foo {
    void m() {
        System.out.println("Foo");
    }
}
abstract class Bar extends Foo {
    abstract void m();
}
public class Test extends Bar {
    void m() {
        // Insert here
    }
    public static void main(String[] args) {
        Foo object = new Test();
        object.m();
    }
}

Which statement can be inserted into the m method of the Test class to make the given program print "Foo" to the console?


Options are :

  • super.m();
  • this.super.m();
  • super.super.m();
  • Foo.m();
  • None of the above

Answer :None of the above

What is the output of the given code?
List list = new ArrayList<>(List.of("A", "B"));
list.removeAll(List.of("B", "C"));
System.out.println(list.get(0) + " " + list.get(1));


Options are :

  • A B
  • A null
  • B B
  • B C
  • null C
  • An IndexOutOfBoundsException is thrown

Answer :An IndexOutOfBoundsException is thrown

What is the program's output?
public class Test {
    static public void main(String[] args) {
        String string1 = "";
        char[] array1 = {'h', 'e', 'y'};
       for (char element : array1) {
            string1 += element;
        }
        String string2 = null;
        String[] array2 = {"h", "e", "y"};
        for (String element : array2) {
            string2 += element;
        }
        String string3 = "hey".intern();
        boolean comp1 = string1.equals(string2);
        boolean comp2 = string2 == string3;
        boolean comp3 = string3 == string1;
        System.out.println(comp1 + " " + comp2 + " " + comp3);
    }
}


Options are :

  • true true true
  • true true false
  • true false true
  • false true false
  • false false true
  • false false false

Answer :false false false

What is the program's output?
public class Test {
    static int i = 0;
    static public void main(String[] args) {
        do {
            for (int i = 0; i < 10; i++) {
                System.out.print(i + " ");
            }
            i++;
        } while (i < 5);
    }
}


Options are :

  • 2000 2 4
  • 0 2 4 6 8
  • It prints all digits from 0 to 4, repeated ten times
  • It prints all digits from 0 to 9, repeated five times
  • It runs into an infinite loop
  • Compilation fails

Answer :It prints all digits from 0 to 9, repeated five times

Which of the following is not a valid command to launch an application?


Options are :

  • java main-class
  • java -jar jar-file
  • java -m module/main-class
  • java source-file
  • None of the above

Answer :None of the above

Which command can be used to analyze Java class dependencies in the module system?


Options are :

  • java
  • javac
  • jdeps
  • jmod

Answer :jdeps

Which of the following is not a feature of the Java language?


Options are :

  • Complex
  • Object-oriented
  • Robust
  • Secure

Answer :Complex

Which three lines are valid?
byte b = 100; // Line 1
char c = b; // Line 2
short s = c; // Line 3
float f = s; // Line 4
long l = f; // Line 5
double d = l; // Line 6


Options are :

  • Line 1
  • Line 2
  • Line 3
  • Line 4
  • Line 5
  • Line 6

Answer :Line 1 Line 4 Line 6

What is the output of the given code fragment?
List list = new ArrayList<>(List.of("A"));
String[] array1 = {"B", "C"};
String[] array2 = list.toArray(array1);
array1[1] = "D";
System.out.println(Arrays.toString(array2));


Options are :

  • [A]
  • [A, C]
  • [A, D]
  • [B, C]
  • [B, D]
  • [D]

Answer :[A, D]

Given four methods:
void loop1() {
    while (0 != 0) {
        System.out.println("inside");
    }
    System.out.println("outside");
}
void loop2() {
    while (0 == 0) {
        System.out.println("inside");
    }
    System.out.println("outside");
}
void loop3() {
    int i = 0;
    while (i != 0) {
        System.out.println("inside");
    }
    System.out.println("outside");
}
void loop4() {
    int i = 0;
    while (i == 0) {
        System.out.println("inside");
    }
    System.out.println("outside");
}
Which methods compile successfully?


Options are :

  • loop1 only
  • loop2 only
  • loop3 only
  • loop4 only
  • loop1 and loop2
  • loop3 and loop4

Answer :loop3 and loop4

Which assignment fails to compile?
Object[] array1 = new Object[]{"John", 30}; // Line 1
Object[] array2 = new Object[]{new int[][]{}}; // Line 2
Object[] array3 = new Object[1]{new Object()} ; // Line 3
Object[] array4 = new String[0];  // Line 4
Object[][] array5 = new Integer[][]{?{}};  // Line 5


Options are :

  • Line 1
  • Line 2
  • Line 3
  • Line 4
  • Line 5

Answer :Line 3

What is the program's output?
public class Test {
    int increase(int number) {
        return number++;
    }
    public static void main(String[] args) {
        Test test = new Test();
        int number = test.increase(1);
        number += ++number;
        System.out.println(number);
    }
}


Options are :

  • 1
  • 2
  • 3
  • 4
  • 5
  • Compilation fails

Answer :3

What is the program's output?
public class Address {
    static final String street;
    final int number;
    public Address(String street, int number) {
        this.street = street;
        this.number = number;
    }
    public static void main(String[] args) {
        Address address1 = new Address("High Street", 100);
       Address address2 = new Address("High Street", 100);
        boolean b1 = address1 == address2;
        boolean b2 = address1.equals(address2);
        System.out.println(b1 + " " + b2);
    }
}


Options are :

  • true true
  • true false
  • false true
  • false false
  • Compilation fails

Answer :Compilation fails

What is the given program's output?
class Foo {
    int i;
    Foo() {
        System.out.println("No parameter");
    }
    Foo(int i) {
        this.i = i;
       System.out.println("One parameter");
    }
}
class Bar extends Foo {
    Bar(int i) {
        this();
    }
    Bar() { }
}
And:
public class Test {
    public static void main(String[] args) {
       new Bar(0);
    }
}


Options are :

  • No parameter
  • One parameter
  • No parameter; No parameter
  • No parameter; One parameter
  • One parameter; No parameter
  • One parameter; One parameter

Answer :No parameter

Which two of the following statements are correct about lambda expressions?


Options are :

  • Lambda expressions can only be used where an interface with a single method is expected
  • A lambda expression parameter must be declared with a type or stay on its own (without any preceding keywords)
  • The return keyword is forbidden in the body of a lambda expression
  • Lambda expressions cannot have fields
  • A lambda expression can be passed around just like a normal object

Answer :Lambda expressions cannot have fields A lambda expression can be passed around just like a normal object

Which types can be referenced in the MyTest class by their simple name without the import statement?
package test;
public class MyTest {
    public static void main(String[] args) {
        // a valid body
    }
}


Options are :

  • Types in the java.lang package
  • Types in the test package
  • Types in the test package and all packages starting with test.
  • Types specified in options A and B
  • Types specified in options A and C
  • None of the above as all classes and interfaces must be explicitly imported

Answer :Types specified in options A and B

What is the program's output?
public class Test {
    void increment(int i1, Integer i2) {
        i1++;
        i2++;
    }
    public static void main(String[] args) {
        int i1 = new Integer(0);
        Integer i2 = 0;
        new Test().increment(i1, i2);
        System.out.println(i1 + " " + i2);
    }
}


Options are :

  • 0 0
  • 0 1
  • 1 0
  • 1 1
  • Compilation fails inside the increment method
  • Compilation fails inside the main method

Answer :0 0

Which command lists the modules explicitly required by a target module?


Options are :

  • jdeps -ld
  • jdeps --list-deps
  • jdeps -list-reduction
  • jdeps --list-reduced-deps

Answer :jdeps --list-reduced-deps

What happens when compiling and executing the given code fragment?
List<Integer> list = List.of(1, 2, 3);
for (int i : list) {
    switch (i) {
        case 1: continue;
        case 2: continue;
        default:
    }
    System.out.println(i);
}


Options are :

  • It fails to compile
  • It prints 2 only
  • It prints 3 only
  • It prints 1 and 2
  • It prints 1, 2 and 3
  • It prints nothing

Answer :It prints 3 only

What is the output of the given code fragment?
char[] array1 = {'a'};
Character[] array2 = {'a'};
System.out.println(Arrays.mismatch(array1, array2));


Options are :

  • -1
  • 0
  • 1
  • Compilation fails

Answer :Compilation fails

public class Test {
    int echo(int input) throws IOException {
        if (input < 0) throw new IOException();
        if (input == 0) throw new ArithmeticException();
        return input;
    }
    public static void main(String[] args) {
        Test test = new Test();
        int output;
        try {
            output = test.echo(1); // Line 1
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(output);
    }
}

Which statement is correct about the given program?


Options are :

  • It fails to compile, but changing the argument on line 1 from 1 to 0 will fix the error
  • It fails to compile, but changing the argument on line 1 from 1 to a negative int value will fix the error
  • It fails to compile, but adding ArithmeticException to the throws clause of the echo method will fix the error
  • It fails to compile, and none of the above solutions solves the problem
  • It compiles successfully

Answer :It fails to compile, and none of the above solutions solves the problem

What is the program's output?
int i = 070;
System.out.println(i);


Options are :

  • 70
  • 70
  • 49
  • 56
  • Compilation fails

Answer :56

What is the output of the given code?
List<Integer> numbers = new ArrayList<>();
numbers.add(0); // Line 1
numbers.add(2, 1); // Line 2
numbers.add(1, 2); // Line 3
numbers.remove(2); // Line 4
System.out.println(numbers);


Options are :

  • [0, 1]
  • [0, 2]
  • An exception is thrown on line 1
  • An exception is thrown on line 2
  • An exception is thrown on line 3
  • An exception is thrown on line 4

Answer :An exception is thrown on line 2

Which three of the following statements, when inserted independently into the given code fragment, enable it to print "goodbye" to the console?
StringBuilder builder = new StringBuilder("good bye");
// Insert here
System.out.println(builder);


Options are :

  • builder.delete(4);
  • builder.delete(4, 5);
  • builder.deleteCharAt(4);
  • builder.remove(4);
  • builder.removeCharAt(4);
  • builder.replace(4, 5, "");

Answer :builder.delete(4, 5); builder.deleteCharAt(4); builder.replace(4, 5, "");

Which change can be made to enable the given code to compile?
abstract class Foo {
    abstract void m() throws ArithmeticException; // Line 1
}
abstract class Bar extends Foo {
    abstract void m() throws RuntimeException; // Line 2
}


Options are :

  • Replace ArithmeticException on line 1 with RuntimeException
  • Replace ArithmeticException on line 1 with Exception
  • Replace RuntimeException on line 2 with ArithmeticException
  • Turn both methods into non-abstract by providing them with a body
  • No change is needed as the given code is already able to compile

Answer :No change is needed as the given code is already able to compile

Which variable declarations are valid?
char[][] a1 = {?{'a', 'b'} {'c', 'd', 'e'}};
char[][] a2 = new char[][]{'a', 'b'};
char[][] a3 = new char[]{new char[]{'a'}};
char[][] a4 = {new char[0]};


Options are :

  • a1 only
  • a2 only
  • a3 only
  • a4 only
  • a1 and a2
  • a1 and a3

Answer :a4 only

Which two statements are correct above the given method when it's called?
void check(boolean arg) {
    if (arg)
    arg = !arg;
    if (arg)
    System.out.println("true");
    System.out.println("false");
}


Options are :

  • It always prints "true"
  • It never prints "true"
  • It always prints "false"
  • It never prints "false"
  • It prints "true" if and only if the method argument is true
  • It prints "false" if and only if the method argument is false

Answer :It never prints "true" It always prints "false"

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions