标签:lan break insert pos app exec ever project .class
QUESTION 13423行结束,snooch 和booch都没引用任何对象,可以被垃圾回收器回收。
QUESTION 135
Given:
一定要记得Java的参数传递全部都是引用不变哦
QUESTION 136 Given classes defined intwo different files:
package util;
public class BitUtils {
private static voidprocess(byte[] b) {} //注意这里的访问修饰符是private,在类外不能访问,所以选择F
}
package app;
public class SomeApp {
public static voidmain(String[] args) {
byte[] bytes = new byte[256];
// insert code here
}
What is required at line 5 in classSomeApp to use the process method of BitUtils?
A. process(bytes);
B. BitUtils.process(bytes);
C. app.BitUtils.process(bytes);
D. util.BitUtils.process(bytes);
E. import util.BitUtils.*;process(bytes);
F. SomeApp cannot use the processmethod in BitUtils.
Answer: F
Section: (none)
QUESTION 139
Given the following directory structure:
bigProject
|--source
| |--Utils.java
|
|--classes
|--
And the following
command line invocation: javac -d classes source/Utils.java Assume the current directory is bigProject,
what is the result?
A. If the compile is successful, Utils.class is added to the source directory.
B. The compiler returns an invalid flag error.
C. If the compile is successful, Utils.class is added to the classes directory.
D. If the compile is successful, Utils.class is added to the bigProject directory.
Answer: C
-d classes 是把生成的Utils.class文件放到classes目录中的Unix命令~~
QUESTION 140 Given:
interface Fish { }
class Perch implements Fish { }
class Walleye extends Perch { }
class Bluegill { }
public class Fisherman {
public static voidmain(String[] args) {
Fish f = new Walleye();
Walleye w = new Walleye();
Bluegill b = new Bluegill();
if(f instanceof Perch)System.out.print("f-p ");
if(w instanceof Fish)System.out.print("w-f ");
if(b instanceof Fish)System.out.print("b-f ");
}
What is the result?
A. w-f
B. f-p w-f
C. w-f b-f
D. f-p w-f b-f
E. Compilation fails.
F. An exception is thrown atruntime.
Answer: B
a instanceof b,指的是a对象是否是b类或其子类的一个实例对象
或者说a对象是否是实现了b接口的一个实例对象。
w对象是Perch子类的实例对象,f对象实现了Fish接口,b对象没有实现Fish接口。
QUESTION 141
Given:
Answer: B
QUESTION 142 Given:
public void testIfA() {
if (testIfB("True")){
System.out.println("True");
} else {
System.out.println("Nottrue");
}
}
public Boolean testIfB(Stringstr) {
return Boolean.valueOf(str);
What is the result when method testIfA isinvoked?
A. True
B. Not true
C. An exception is thrown atruntime.
D. Compilation fails because of anerror at line 12.E. Compilation fails because of an error at line 19.
Answer: A
public static Boolean valueOf(String s)返回一个用指定的 String 表示值的 Boolean 值。如果 String 参数不为 null 且在忽略大小写时等于 "true",则返回的 Boolean 表示 true 值。
QUESTION 143 Given:
public class Donkey {
public static voidmain(String[] args) {
boolean assertsOn = false;
assert (assertsOn) : assertsOn= true;
if(assertsOn) {
System.out.println("assertis on");
}
}
If class Donkey is invoked twice, thefirst time without assertions enabled, and the second time with assertionsenabled, what are the results?
A. no output
B. no output
assert is on
C. assert is on
D. no output
An AssertionError is thrown.ss
E. assert is on
An AssertionError is thrown.
QUESTION 144
Given:
finally有几种情况可以执行:正常执行,发生异常被catch块处理,当然,在catch块内发生的异常也行。
QUESTION 145
Given:
x=0 y=0 -->o-->00
x=0 y=1 -->o-->00+01->0001
x=1 y=0 1 2--> break;
x=2 y=0 o-->0001+20-->000120
x=2 y=1 break;
最终结果是C
QUESTION 146
Given:
我写了一点测试了一下,发现如果字符串为空(null),那么toString()函数会抛出NullPointerException异常,而不去转换直接输出的时候不会。
[java] view plain copy
package com.xujin;
public class Test {
public static void main(String[] args) {
String s = null;
System.out.println(s);//null
//System.out.println(s.toString());//NullPointerException
System.out.println(s + "hello~~");//nullhello~~
}
}
QUESTION 147 Given:
interface Foo {}
class Alpha implements Foo {}
class Beta extends Alpha {}
class Delta extends Beta {
public static void main(String[] args ) {
Beta x = new Beta();
// insert code here
}
Which code, inserted at line 16, willcause a java.lang.ClassCastException?
A. Alpha a = x;
B. Foo f = (Delta)x;
C. Foo f = (Alpha)x;
D. Beta b = (Beta)(Alpha)x;
Answer: B
架设Foo是飞接口
//Alpha a=x; //将子类转化为父类对象允许,动物 a=狗
//Foo f=(Delta)x;//将鸽子抓换为fei接口对象
//Foo f=(Alpha)x; //鸟-->飞对象f实现了飞接口的鸟对象
QUESTION 148
Given:
本处意思,如果在34行出现了异常,则最可能是ac或bc,但是没有bc,则选D
QUESTION 149 Given:
public class Test {
public enum Dogs {collie,harrier, shepherd};
public static void main(String[] args) {
Dogs myDog = Dogs.shepherd;
switch (myDog) {
case collie:
System.out.print("collie");
case default:
System.out.print("retriever");
case harrier:
System.out.print("harrier");
}
}
What is the result?
A. harrier
B. shepherd
C. retriever
D. Compilation fails.
E. retriever harrier
F. An exception is thrown atruntime.
Answer: D
d,错在了case default,有default,前面不用加case
标签:lan break insert pos app exec ever project .class
原文地址:http://blog.51cto.com/2096101/2136771