Given the following class definition which of the following can be legally placed after the comment line //Here ?
class Base{ public Base(int i){} } public class MyOver extends Base{ public static void main(String arg[]){ MyOver m = new MyOver(10); } MyOver(int i){ super(i); } MyOver(String s, int i){ this(i); //Here } }
A.
MyOver m = new MyOver();
B.
super();
C.
this("Hello",10);
D.
Base b = new Base(10);(正确)
2-2
分数 2
作者 翁恺
单位 浙江大学
Given the following code:
public class Test{ public static void main(String args[]) { String str=new String("World"); char ch[]={'H','e','l','l','o'}; change(str,ch); System.out.println(str + "and" + ch); } public static void change(String str, char ch[]) { str="Changed"; ch[0]='C'; } }
What is the result after execution?
A.
World and Hello
B.
World and Cello(正确)
C.
Changed and Hello
D.
Changed and Cello
2-3
分数 2
作者 翁恺
单位 浙江大学
What will be printed out if this code is run with the following command line?
java myprog good morning
public class myprog{ public static void main(String argv[]) { System.out.println(argv[2]) } }
A.
Myprog
B.
Good
C.
Morning
D.
Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"(正确)
2-4
分数 2
作者 翁恺
单位 浙江大学
What will happen when you attempt to compile and run this code?
public class MyMain{ public static void main(String argv){ System.out.println("Hello cruel world"); } }
A.
The compiler will complain that main is a reserved word and cannot be used for a class(正确)
B.
The code will compile and when run will print out "Hello cruel world"
C.
The code will compile but will complain at run time that no constructor is defined
D.
The code will compile but will complain at run time that main is not correctly defined
2-5
分数 2
作者 翁恺
单位 浙江大学
Which function below is the starting point of a Java class?
A.
public static void main(String[] args);(正确)
B.
public static void main();
C.
public static int main(String[] args);
D.
public static void main(int argc, *char[] argv);
2-6
分数 2
作者 翁恺
单位 浙江大学
For the code below, which one can replace the line 7?( )
public class Base { int w,x,y,z; public Base(int a, int b) { x=a;y=b; } public Base(int a, int b, int c, int d) { x=a;y=b; // line 7 w=d;z=c; } }
A.
Base(a,b)
B.
this(a,b,x,y)
C.
this(a,b)(正确)
D.
Base(x,y)
2-7
分数 2
作者 翁恺
单位 浙江大学
Which expression below is for generating a random number of [20,999]?
A.
(int)(20+Math.random()*979)
B.
20+(int)(Math.random()*980)(正确)
C.
(int)Math.random()*999
D.
20+(int)Math.random()*980