报名本机构合作学校,赠送复习资料,复习课程,确保录取。并且可以申请学校奖学金500元~1500元不等!
第二章 Java泛型 测验
1、【单选题】给定代码import java.util.*;
class WashT ____________ Collection
{
T item;
public void clean(T items) {
System.out.println(Cleaned + items.size() + items);
}
}
public class LaundryTime {
public static void main(String[] args) {
WashList wash = new ____________
wash.clean(Arrays.asList(sock, tie));
}
}下列选项哪个可以添加到程序中,并输出Cleaned 2 items。
A、extends, Wash<ArrayList>();
B、extends, Wash<List>();
C、super, Wash<ArrayList>();
D、super, Wash<List>();
2、【单选题】给定以下代码import java.util.*;
public class ExtendingGenerics {
private static _____________ , U U add(T list, U element) {
list.add(element);
return element;
}
public static void main(String[] args) {
ListString values = new ArrayList();
add(values, duck);
add(values, duck);
add(values, goose);
System.out.println(values);
}
}以下哪个代码添加进去,可以使得程序正常编译。
A、? extends Collection<U>
B、? implements Collection<U>
C、T extends Collection<U>
D、T implements Collection<U>
3、【单选题】给定以下代码import java.io.*;
class LastErrorT {
private T lastError;
public void setError(T t){
lastError = t;
System.out.println(LastError: setError);
}
}
class StrLastErrorS extends CharSequence extends LastErrorString{
public StrLastError(S s) {}
public void setError(S s){
System.out.println(StrLastError: setError);
}
}
class Test {
public static void main(String[] args) {
StrLastErrorString err = new StrLastErrorString(Error);
err.setError(Last error);
}
}其输出结果是
A、It prints the following: StrLastError: setError.
B、It prints the following: LastError: setError.
C、It results in a compilation error.
D、It results in a runtime exception.
4、【判断题】以下代码能够编译通过.public final class Algorithm {
public static T T max(T x, T y) {
return x y ? x : y;
}
}
A、正确
B、错误
5、【判断题】以下代码能够编译通过.public static void print(List? extends Number list)
{
for (Number n : list)
System.out.print(n + );
System.out.println();
}
A、正确
B、错误
6、【判断题】以下代码可以编译通过。public class SingletonT
{
public static T getInstance()
{
if (instance == null)
instance = new SingletonT();
return instance;
}
private static T instance = null;
}
A、正确
B、错误
7、【判断题】给定以下代码,class Shape { /* ... */ }
class Circle extends Shape { /* ... */ }
class Rectangle extends Shape { /* ... */ }
class NodeT { /* ... */ }那以下代码可以编译通过。NodeCircle nc = new Node();
NodeShape ns = nc;
A、正确
B、错误
8、【判断题】给定以下代码,class NodeT implements ComparableT
{
public int compareTo(T obj) { /* ... */ }
// ...
}那以下代码可以编译通过。NodeString node = new Node();
ComparableString comp = node;
A、正确
B、错误
9、【判断题】以下Pair泛型类public class PairK, V {
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey(); { return key; }
public V getValue(); { return value; }
public void setKey(K key) { this.key = key; }
public void setValue(V value) { this.value = value; }
private K key;
private V value;
}经过类型擦除后,变成以下类public class Pair {
public Pair(Object key, Object value) {
this.key = key;
this.value = value;
}
public Object getKey() { return key; }
public Object getValue() { return value; }
public void setKey(Object key) { this.key = key; }
public void setValue(Object value) { this.value = value; }
private Object key;
private Object value;
}
A、正确
B、错误
10、【判断题】以下代码public static T extends ComparableT
int findFirstGreaterThan(T[] at, T elem) {
// ...
}经过类型擦除,变成public static int findFirstGreaterThan(Object[] at, Object elem) {
// ...
}
A、正确
B、错误
第三章 Java反射 作业
第四章 Java代理 作业
第五章 Java注解 单元作业
第六章 嵌套类 单元测验
1、【单选题】Which of the following class types cannot be marked final or abstract?
A、Static nested class
B、Local inner class
C、Anonymous inner class
D、Member inner class
2、【单选题】A local inner class can access which type of local variables (JDK 8+)?I. finalII. privateIII. effectively final
A、I only
B、I and II
C、III only
D、I and III
3、【单选题】What statement best describes the notion of effectively final in Java?
A、A local variable that is marked final.
B、A local variable that is marked final.
C、A local variable that is not marked final but whose primitive value or object reference does not change after it is initialized.
D、A local variable that is not marked final but whose primitive value or object reference does not change after a certain point in the method.
4、【单选题】Which of the following cannot include a static method in its definition?
A、Abstract class
B、Static nested class
C、Interface
D、Local inner class
5、【单选题】What is the output of the following application?package world;
public class Matrix {
private int level = 1;
class Deep {
private int level = 2;
class Deeper {
private int level = 5;
public void printReality() {
System.out.print(level);
System.out.print( + Matrix.Deep.this.level);
System.out.print( + Deep.this.level);
}
}
}
public static void main(String[] bots) {
Matrix.Deep.Deeper simulation = new Matrix().new Deep().new Deeper();
simulation.printReality();
}
}
A、1 1 2
B、5 2 2
C、5 2 1
D、The code does not compile.
6、【单选题】What is the output of the following application?package space;
public class Bottle {
public static class Ship {
private enum Sail { // w1
TALL {
protected int getHeight() {
return 100;
}
},
SHORT {
protected int getHeight() {
return 2;
}
};
protected abstract int getHeight();
}
public Sail getSail() {
return Sail.TALL;
}
}
public static void main(String[] stars) {
Bottle bottle = new Bottle();
Ship q = bottle.new Ship(); // w2
System.out.print(q.getSail());
}
}
A、TALL
B、The code does not compile because of line w1.
C、The code does not compile because of line w2.
D、The code compiles but the application does not produce any output at runtime.
7、【单选题】What is the output of the following application? package forest;
public class Woods {
static class Tree {
}
public static void main(String[] leaves) {
int water = 10 + 5;
final class Oak extends Tree { // p1
public int getWater() {
return water; // p2
}
}
System.out.print(new Oak().getWater());
}
}
A、15
B、The code does not compile because of line p1.
C、The code does not compile because of line p2.
D、None of the above
8、【单选题】What is the output of the following application?package zoo;
public class Penguin {
private int volume = 1;
private class Chick {
private static int volume = 3;
void chick() {
System.out.print(Honk( + Penguin.this.volume + )!);
}
}
public static void main(String... eggs) {
Penguin pen = new Penguin();
final Penguin.Chick littleOne = pen.new Chick();
littleOne.chick();
}
}
A、 Honk(1)!
B、 Honk(3)!
C、The code does not compile.
D、The code compiles but the output cannot be determined until runtime.
9、【单选题】Given the class declaration below, what expression can be used to fill in the blank to return the size variable defined in the Bottle class, printing 14 at runtime?package baby;
final public class Bottle {
final private int size = 14;
final protected class Insert {
private final int size = 25;
public final int getSize() {
return ____________________;
}
}
final Insert insert = new Insert();
final public static void main(String[] feed) {
System.out.print(new Bottle().insert.getSize());
}
}
A、Bottle.this.size
B、this.size
C、this.Bottle.size
D、The code does not compile, regardless of what is placed in the blank.
10、【单选题】The code does not compile, regardless of what is placed in the blank.package present;
interface Toy {
String play();
}
public class Gift {
public static void main(String[] matrix) {
abstract class Robot {
}
class Transformer extends Robot implements Toy {
public String name = GiantRobot;
public String play() {
return DinosaurRobot;
}
}
Transformer prime = new Transformer() {
public String play() {
return name; // y1
}
};
System.out.print(prime.play() + + name);
}
}
A、GiantRobot GiantRobot
B、GiantRobot DinosaurRobot
C、The code does not compile because of line y1.
D、None of the above
第七章 Lambda表达式 单元作业
第八章 Java Stream流 单元测验
1、【单选题】Which can fill in the blank to have the code print true? StreamInteger stream = Stream.iterate(1, i - i+1);
boolean b = stream.__________(i - i 5);
System.out.println(b);
A、anyMatch
B、allMatch
C、noneMatch
D、None of the above
2、【单选题】What is the result of the following?IntStream s = IntStream.empty();
System.out.print(s.average().getAsDouble());
A、The code prints 0.
B、The code prints 0.0.
C、The code does not compile.
D、The code compiles but throws an exception at runtime.
3、【单选题】What is the result of the following?ListDouble list = new ArrayList();
list.add(5.4);
list.add(1.2);
OptionalDouble opt = list.stream().sorted().findFirst();
System.out.println(opt.get() + + list.get(0));
A、1.2 1.2
B、1.2 5.4
C、5.4 5.4
D、None of the above
4、【单选题】Which of the following creates an Optional that returns true when calling opt.isPresent()?I. OptionalString opt = Optional.empty();
II. OptionalString opt = Optional.of(null);
III. OptionalString opt = Optional.ofNullable(null);
A、I
B、I and II
C、I and III
D、None of the above
5、【单选题】If this method is called with Stream.of(hi), how many lines are printed?public static void print(StreamString stream) {
ConsumerString print = System.out::println;
stream.peek(print)
.peek(print)
.map(s - s)
.peek(print)
.forEach(print);
}
A、Three
B、Four
C、The code compiles but does not output anything.
D、The code does not compile.
6、【单选题】Suppose you have a stream pipeline where all the elements are of type String. Which of the following can be passed to the intermediate operation sorted()?
A、(s,t) -> s.length() - t.length()
B、String::isEmpty
C、Both of these
D、Neither of these
7、【单选题】Fill in the blanks so that both methods produce the same output for all inputs.private static void longer(OptionalBoolean opt) {
if (opt.____________())
System.out.println(run: + opt.get());
}
private static void shorter(OptionalBoolean opt) {
opt.map(x - run: + x).____________(System.out::println);
}
A、isNotNull, isPresent
B、ifPresent, isPresent
C、isPresent, forEach
D、isPresent, ifPresent
8、【单选题】What is the output of the following?StreamString s = Stream.of(over the river,
through the woods,
to grandmother's house we go);
s.filter(n - n.startsWith(t))
.sorted(Comparator::reverseOrder)
.findFirst()
.ifPresent(System.out::println);
A、over the river
B、through the woods
C、to grandmother's house we go
D、None of the above
9、【单选题】What does the following output? StreamCharacter chars = Stream.generate(() - 'a');
chars.filter(c - c 'b')
.sorted()
.findFirst()
.ifPresent(System.out::print);
A、a
B、The code runs successfully without any output.
C、The code enters an infinite loop.
D、The code compiles but throws an exception at runtime.
10、【单选题】Which can fill in the blank so this code outputs Caught it?public class Tenth {
public static void main(String[] args) {
Optional opt = Optional.empty();
try {
apply(opt);
} catch (IllegalArgumentException e) {
System.out.println(Caught it);
}
}
private static void apply(OptionalException opt) {
opt._____________(IllegalArgumentException::new);
}
}
A、orElse
B、orElseGet
C、orElseThrow
D、None of the above. The main() method does not compile.
微信扫码添加好友
如二维码无法识别,可拨打 13662661040 咨询。