全国软考程序员考试部分例题全国软考程序员考试部分例题全国软考程序员考试部分例题例题1:choosethethreevalididentifiersfromthoselistedbelow
idolikethelongnameclassb
$bytec
constd
3_case解答:a,b,d点评:java中的标示符必须是字母、美元符($)或下划线(_)开头
关键字与保留字不能作为标示符
选项c中的const是java的保留字,因此不能作标示符
选项e中的3_case以数字开头,违反了java的规则
例题2:howcanyouforcegarbagecollectionofanobject
garbagecollectioncannotbeforcedb
callsystem
callsystem
gc(),passinginareferencetotheobjecttobegarbagecollected
callruntime
setallreferencestotheobjecttonewvalues(null,forexample)
解答:a点评:在java中垃圾搜集是不能被强迫立即执行的
调用system
gc()或runtime
gc()静态措施不能保证垃圾搜集器的立即执行,由于,也许存在着更高优先级的线程
因此选项b、d不对的
选项c的错误在于,system
gc()措施是不接受参数的
选项e中的措施可以使对象在下次垃圾搜集器运行时被搜集
例题3:considerthefollowingclass:1
classtest(inti){2
voidtest(inti){3
system
println(iamanint
voidtest(strings){6
system