1、
assert (x > 0) ? "assertion failed" : "assertion passed"; 那么就会编译报错, 因为断言并没有此种形式
F. Compilation fails.
4、
Given:
1. public class OuterClass {
2. private double d1 = 1.0;
3. // insert code here
4. }
Which two are valid if inserted at line 3? (Choose two)
A. static class InnerOne {
public double methoda() { return d1; }
}
B. static class InnerOne {
static double methoda() { return d1; }
}
C. private class InnerOne {
public double methoda() { return d1; }
}
D. protected class InnerOne {
static double methoda() { return d1; }
}
E. public abstract class InnerOne {
public abstract double methoda();
}
关于内部类的问题一直没有搞得很明白, 参考《Thinking in java》!
5、
Given:
1. public class Foo {
2. public void main( String[] args ) {
3. System.out.println( "Hello" + args[0] );
4. }
5. }
What is the result if this code is executed with the command line?
java Foo world
A. Hello
B. Hello Foo
C. Hello world
D. Compilation fails.
E. The code does not run.
解析: 要先编译,也即要先使用javac命令才可以。
补充: *String[] args: args是“参数”的缩写,可以改成任意的名字。
args存贮的是命令行参数,可用于程序中。
*支持从命令行输入参数:
String[] args这个字符串数组是保存运行main函数时输入的参数 的,例如 main函数所在的类名为test那么你在cmd运行java test a b c时
args[0]=a,args[1]=b,args[2]=c,你就可以在你的程序中调用你输入的这些变量。
当然也可以在IDE中进行次试验, 如果IDE是eclipse,那么你只要在运行的时候点右键,选open run dialog,然后选arguments选项卡,然后在program arguments中输入两个参数就行了。两个参数间用空格隔开就行了 。