java基础学习阶段性测试Word文档格式.docx
- 文档编号:17419654
- 上传时间:2022-12-01
- 格式:DOCX
- 页数:13
- 大小:19.54KB
java基础学习阶段性测试Word文档格式.docx
《java基础学习阶段性测试Word文档格式.docx》由会员分享,可在线阅读,更多相关《java基础学习阶段性测试Word文档格式.docx(13页珍藏版)》请在冰豆网上搜索。
7.//....
8.intx;
9.switch(x){
10.case0:
11.{
12.intvar;
13.//process
14.}
15.break;
16.case1:
17.{
18.intvar1;
19.//process
20.}
21.break;
22.}
A、1和16行之间B、4和8行之间C、6和8行之间D、6和14行之间
7.以下的类(接口)定义中正确的是(B)。
A.
publicclassa{
privateintx;
publicgetX(){
returnx;
B.
publicabstractclassa{
publicabstractintgetX();
publicintaMethod(){
return0;
C.
D.
publicinterfaceinterfaceA{
publicintgetX(){
8.已知A类被打包在packageA
B类被打包在packageB
,且B类被声明为public
,且有一个成员变量x被声明为protected控制方式
。
C类也位于packageA包,且继承了B类
则以下说话正确的是(C)(选择一项)
A.A类的实例不能访问到B类的实例
B.A类的实例能够访问到B类一个实例的x成员
C.C类的实例可以访问到B类一个实例的x成员
D.C类的实例不能访问到B类的实例
9.编译并运行下面的Java代码段:
char
c='
a'
switch
(c)
{
case
'
:
"
a"
);
default:
default"
输出结果是(B)。
A.代码无法编译,因为switch语句没有一个合法的表达式
B.aDefault
C.a
D.default
10.在Java中,关于final关键字的说法正确的是(AC)。
(选择两项)
A.如果修饰变量,则一旦赋了值,就等同一个常量
B.如果修饰类,则该类只能被一个子类继承
C.如果修饰方法,则该方法不能在子类中被覆盖
D.如果修饰方法,则该方法所在的类不能被继承
11.在Java中,要想使只有定义该类所在的包内的类可以访问该类,应该用(A)关键字。
A.不需要任何关键字
B.private
C.final
D.protected
12.在Java中,下面关于包的陈述中正确的是(AD)。
A.包的声明必须是源文件的第一句代码
B.包的声明必须紧跟在import语句的后面
C.只有公共类才能放在包中
D.可以将多个源文件中的类放在同一个包中
13.public
static
void
main方法的参数描述是:
(请选择2个正确答案)AB
A.String
args[]
B.String[]
args
C.Strings
args[]z
D.String
14.编译并运行下面的Java程序:
class
A{
int
var1=1;
var2;
public
main(String[]
args){
var3=3;
A
a=new
A();
将产生(B)结果。
A.0
B.4
C.3
D.代码无法编译,因为var2根本没有被初始化
15.编译,运行下列代码后的结果是:
(选择一项)D
Test
public
main
(String
args
[])
int
age;
age
=
age
+
1;
The
is
"
age);
A.编译,运行后没有输出
B.编译,运行后输出:
1
C.能通过编译,但运行时产生错误
D.不能通过编译
16.下列哪些表达式返回true:
(请选择2个正确答案
)AB
A."
john"
==
B."
.equals("
)
C."
D."
.equals(new
Button("
))
17.Give
the
code
fragment:
BC
1)switch(x){
2)
1:
1”);
break;
3)
2:
4)
3:
2”);
5)
6)
}
which
value
of
x
would
cause
“Test
2”
to
output:
A.
1B.
2C.
3D.
default
18.Given
following
definition:
A
A{
protected
i;
A(int
i){
this.i=i;
be
a
valid
inner
for
this
class?
Select
all
answers:
B{
B.class
B
extends
C.class
B(){;
D.class
A{}
E.class
A{}
19.The
entire
contents
file
called
Example.java,causes
precisely
one
error
during
compilation:
D
1)class
SubClass
BaseClass{
}
3)class
4)
String
str;
5)
BaseClass(){
;
7)
public
BaseClass(String
s){
str=s;
9)}
10)public
Example{
11)
method(){
12)
SubClass
s=new
SubClass(“hello”);
13)
BaseClass
b=new
BaseClass(“world”);
14)
15)
Which
line
error?
9B.
10C.
11D.12
20.Float
Float(0.9F);
Float
t=new
Double
u=new
Double(0.9);
expression’s
result
true?
B
s=
=tB.
s.equals(t)C.
=uD.
t.equals(u)
21.What
happens
when
you
try
compile
and
run
program?
E
Mystery{
String
s;
args){
Mystery
m=new
Mystery();
m.go();
void
Mystery(){
s=”constructor”;
go(){
;
A.this
will
not
B.this
but
throws
an
exception
at
runtime
C.this
runs
nothing
appears
in
standard
output
D.this
“constructor”
E.this
writes
”null”
output
22.Give
class:
str=new
String(“good”);
char
ch[]={‘a’,’b’,’c’};
main(String
args[]){
Example
ex=new
Example();
ex.change(ex.str,ex.ch);
+ex.ch[1]
+ex.ch[2]);
change(String
str,char
ch[]){
str=”test
ok”;
ch[0]=’g’;
good
abcB.
gbcC.
test
ok
abcD.
gbc
23.Which
correctly
create
two
dimensional
array
integers?
CDE
A.int
a[][]
new
int[][];
B.int
a[10][10]
C.int
int[10][10];
D.int
[][]a
E.int
[]a[]
24.Examine
includes
final
Test4
implements
class
Inner{
test(){
if
(;
{
sample();
private
boolean
flag=false;
sample(){
Test4(){
(new
Inner()).test();
new
Test4();
What
result:
A.Print
out
“Sample”
B.Program
produces
no
terminates
correctly.
C.
Program
does
terminate.
E.The
program
compile
25.Which
statement
true
about
A.It
must
anonymous
B.It
can
implement
interface
C.It
only
accessible
enclosing
D.It
access
any
variables
scope
26.public
Test{
aMethod(){
i=0;
i++;
return
Test();
test.aMethod();
j=test.aMethod();
result?
A.Compilation
fail
B.Compilation
succeed
print”0”.
C.Compilation
print”1”.
D.Compilation
print”2”
27.class
Super{
Super(String
text){
i=1;
Sub
Sub(String
text){
i=2;
ag[]){
sub=new
Sub(“Hello”);
print”1”
28.Given
Package
foo;
Outer{
A.An
instance
Inner
constructed
with
“new
Outer.Inner():
B.An
cannot
outside
package
C.An
from
within
Outer
class.
D.From
bar,
Inner()”
29.What
s=”Hello”;
t.methodA(s);
methodA(String
s+=”World”;
A.print
“Hello”
B.print
“World”
C.print
“Hello
World”
30.
what
C
String(”true”);
Boolean
Boolean(true);
If(s.equals(b))
“hello”
B.compile
6
C.compile
D.compile
throw
runtime
二、编程题:
1.用循环控制语句打印输出:
1+3+5+…….+99=?
结果。
2.编写两个方法分别计算组合数n!
.
一个使用递归方法实现,另一个不用递归方法。
3.编写如下的代码:
A.这个数组应该有以下方法.
sort(Object[]a)
sort(Object[]o,Comparatorc)
它们应该能对任何数据对象类型的数组进行排序。
find(Object[]o,Objectb)
要求采用二分查找的方式,对排序后的数组,查找特定的元素.
B.创建一个学生类,学生有如下属性
id(唯一),name,address,code,nickName,age
C.创建一个具有10个学生类型元素的数组,首先根据id,利用ArraysUtil.sort(Object[]a)方法对它进行排序;
然后,根据id,查找一个特定的学生(二分查找)。
D.最后,再用sort(Object[],Comparatorc)方法,对这个数组重新排序(先按姓名,再按地址排序的排序规则)。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 基础 学习 阶段性 测试