软件工程师(Java)初级阶段测试题
一、选择题:(每题2分)
1.
名为HelloWorld.java的Java应用程序如下:
public class
HelloWorld
{
public static void main(String
args[])
{
System.out.println("Hello
World!");
}
}
将这个程序放在C:\Test下,然后在命令行窗口中,进入到C:\Test路径执行如下指令:
javac helloworld.java将得到( )结果。
A.
编译出错。
B.
编译成功,生成名为HelloWorld.class的文件。
C.
编译成功,生成名为helloworld.class的文件。
D.
找不到名为helloworld.java的文件。
答案: D。在JAVA中是严格区分大小写的
2.
下面的程序名为Student.java:
public class Student
{
private String name;
public Student(String
s_name) //1
{
name =
s_name; //2
}
public static void main(String args[])
{
Student s = new
Student(); //3
}
}
使用如下指令编译:javac Student.java。将会得到的结果( )。
A.
将会顺利通过编译,并将产生一个Student.class的类文件。
B.
编译时在//3处出错。
C.
编译时在//2处出错。
D.
编译时在//1处出错。
答案:B。因为Student的构造函数是带有参数的构造函数。
3.
关于下面的类描述中正确的是( )。
class Test
{
// 1
void test(int i)
{
// 2
System.out.println("I am an
int.");
// 3
}
// 4
void test(String s)
{
// 5
System.out.println("I am a
string.");
// 6
}
// 7
// 8
public static void main(String args[])
{
// 9
Test t=new
Test();
// 10
char
ch='y';
// 11
t.test(ch);
// 12
}
// 13
}
// 14
A.
编译出错
B.
编译通过,运行出错
C.
编译通过,运行时输出“I am
an int”
D.
编译通过,运行时输出“I am
a string”
答案:C。字符在ASCii码中是以整数形式存在的。
4.
关于下述程序:
public class Test3
{
public static void main(String[] agrs)
{
byte b = 2,e =3;
//1
byte f = b+e;
//2
System.out.println(f); //3
}
}
描述正确的是( )。
A.
编译通过,运行时打印出5。
B.
编译通过,运行时打印出23。
C.
编译不通过,在//2处有错误,因为此处f必须是一个int类型的变量。
D.
编译不通过,在//1处有错误,不能这样定义变量
答案:C
5.
在Java中,关于让垃圾回收器强制回收对象的说法中,正确的是( )。
A.垃圾回收不能强制
<