Q1. Given: What is the result?
A. Initialized Started
B. Initialized Started Initialized
C. Compilation fails
D. An exception is thrown at runtime
Answer: B
Q2. Given:
public class SampleClass {
public static void main(String[] args) {
AnotherSampleClass asc = new AnotherSampleClass(); SampleClass sc = new
SampleClass();
sc = asc;
System.out.println("sc: " + sc.getClass());
System.out.println("asc: " + asc.getClass());
}}
class AnotherSampleClass extends SampleClass {
}
What is the result?
A. sc: class Object asc: class AnotherSampleClass
B. sc: class SampleClass asc: class AnotherSampleClass
C. sc: class AnotherSampleClass asc: class SampleClass
D. sc: class AnotherSampleClass asc: class AnotherSampleClass
Answer: D
Q3. Which two statements are true for a two-dimensional array of primitive data type?
A. It cannot contain elements of different types.
B. The length of each dimension must be the same.
C. At the declaration time, the number of elements of the array in each dimension must be specified.
D. All methods of the class object may be invoked on the two-dimensional array.
Answer: C,D
Explanation: http://stackoverflow.com/questions/12806739/is-an-array-a-primitive-type-or-an-object-or-something-else-entirely
Q4. 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: B
Q5. Given the code fragment:
List<Integer> list1 = Arrays.asList(10, 20);
List<Integer> list2 = Arrays.asList(15, 30);
//line n1
Which code fragment, when inserted at line n1, prints 10 20 15 30?
A. Stream.of(list1, list2)
.flatMap(list -> list.stream())
.forEach(s -> System.out.print(s + “ “));
B. Stream.of(list1, list2)
.flatMap(list -> list.intStream())
.forEach(s -> System.out.print(s + “ “));
C. list1.stream()
.flatMap(list2.stream().flatMap(e1 -> e1.stream())
.forEach(s -> System.out.println(s + “ “));
D. Stream.of(list1, list2)
.flatMapToInt(list -> list.stream())
.forEach(s -> System.out.print(s + “ “));
Answer: C
Q6. 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 { }
Answer: A,E
Explanation: extends is for extending a class.
implements is for implementing an interface. Java allows for a class to implement many interfaces.