wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java_A

Total questions: 29

Worksheet time: 29mins

Name
Class
Date
1.

1. 下列选项中,( )是 JDK 提供的编译器。

a)

A. java.exe

b)

B. javac.exe

c)

C. javaw.exe

d)

D. javap.exe

2.

下列叙述错误的是( )。

a)

A. System 是关键字。

b)

B. _class 可以作为标识符。

c)

C. Char 型字符在 Unicode 表中的位置范围为 0-65535。

d)

D. 对于“int a[] = new int[5];”,a.length 的值是 5。

3.

3. 对于 int[][] a = {{1,2},{1,2,3},{1,2,3,4}}; 下列叙述错误的是( )

a)

A. a.length 的值是3

b)

B. a[2].length 的值是 4。

c)

C. a[0][1]的值是 1。

d)

D. a[2][0]的值是 1。

4.

4. 对于“int n = 5678;”,表达式的值为 6 的是( )。

a)

A. n%10

b)

B. n/10%10

c)

C. n/100%10

d)

D. n/1000%10

5.

5. 对于 Test.java,下列叙述正确的是( )。

public class Test{

public static void main(String[] args){

boolean boo = false;

if(boo == true){

System.out.print(“Hello”);

System.out.print(“你好”); }

else{

System.out.print(“ok”);

System.out.print(“yes”); } } }

a)

A. 出现编译错误。

b)

B. 程序的输出结果是 hello 你好。

c)

C. 程序的输出结果是 ok。

d)

D. 程序的输出结果是 okyes。

6.

6. 下列叙述正确的是( )

a)

A.成员变量有默认值。

b)

B. this 可以出现在 static 方法中。

c)

C. 类中的实例方法可以用类名调用。

d)

D. 局部变量也可以用权限修饰符 public、protected、private 修饰。

7.

7. 对于下列代码,叙述正确的是( )。

public class Test{

public static void main(String[] args){

Tom cat = new Tom(); } }

class Tom{

void Tom(){

System.out.println(“ok”); }

Tom(){

System.out.println(“你好”); } }

a)

A. 程序运行时输出:ok。

b)

B. 有两个构造方法。

c)

C. 有编译错误。

d)

D. 程序运行时输出:你好。

8.

8. 下列关于类方法(static 方法)和实例方法,叙述错误的是( )

a)

A. 类方法可以用类名调用。

b)

B. 实例方法可以操作 static 变量。

c)

C. 类方法可以操作实例变量。

d)

D. 类方法可以操作 static 变量。

9.

9. 下列选项中关于 Java 中封装的说法错误的是( )

a)

A. 封装就是将属性私有化,提供共有的方法访问私有属性。

b)

B. 属性的访问方法包括 setter 方法和 getter 方法。

c)

C. setter 方法用于赋值,getter 方法用于取值。

d)

D. 包含属性的类都必须封装属性,否则无法通过编译。

10.

10.下列关于类的继承,叙述正确的是( )。

a)

A. 一个类可以同时继承多个父类。

b)

B. 一个父类可以具有多个子类。

c)

C. 子类可以调用父类的所有方法。

d)

D. 子类一定比父类有更多的方法。

11.

11.下列关于 final 关键字,叙述错误的是( )。

a)

A. final 修饰类表明该类是最终类,不能被继承。

b)

B. final 修饰方法表明该方法是最终方法,不能被重写

c)

C. final 修饰变量表示该变量第一次赋值后,不能再次被赋值。

d)

D. 可以同时用 final 和 abstract 修饰一个类。

12.

12.下列关于 abstract 关键字,叙述错误的是( )。

a)

A. abstract 可以修饰类、成员方法。

b)

B. abstract 类中只可以有 abstract 方法

c)

C. abstract 类不能用 new 运算符创建对象。

d)

D. abstract 不能修饰变量、构造方法。

13.

13.下列选项中,用于定义接口的关键字是( )。

a)

A. implements

b)

B. class

c)

C. interface

d)

D. extends

14.

1. Java 程序编译后生成的字节码文件的后缀为.exe。

a)

True

b)

False

15.

2. System.out.println(‘a’+1);的输出结果为 a1。

a)

True

b)

False

16.

3. 对于数组“int a[][] = new int[7][3];”,a.length 的值是 7,a[1].length 和 a[3].length 的值是 3。( )

a)

True

b)

False

17.

4. 表达式“12 = 12”的输出结果为 true。( )

a)

True

b)

False

18.

5. if 语句中的条件表达式的值是布尔类型数据。( )

a)

True

b)

False

19.

6. 方法中声明的局部变量可以用访问修饰符 public、protected、private 修 饰。( )

a)

True

b)

False

20.

7. 一个类中可以有多个名字相同的方法,但这些方法的参数必须不同,即或者 是参数的个数不同,或者是参数的类型不同。( )

a)

True

b)

False

21.

8. 子类继承父类的构造方法。( )

a)

True

b)

False

22.

9. 如果成员变量被 final 修饰,就是常量,用户在声明时可以不指定该常量的 值,编译器会提供默认值。( )

a)

True

b)

False

23.

10. 接口中只能有常量,不能有变量。( )

a)

True

b)

False

24.

下面代码是计算 6+66+666+6666+…的前 10 项和,请在下划线的位置填上适当 的代码。

public class Test1{

public static void main(String[] args){

long sum = 0, a = 6, item = a

int i; //i 为循环变量

for(i = 1; (----(1)----) ; i++){

sum = sum + item;

(-----(2)-----) ; }

System.out.println(sum); } }

(a)  

25.

下面代码是计算 6+66+666+6666+…的前 10 项和,请在下划线的位置填上适当 的代码。

public class Test1{

public static void main(String[] args){

long sum = 0, a = 6, item = a

int i; //i 为循环变量

for(i = 1; (----(1)----) ; i++){

sum = sum + item;

(-----(2)-----) ; }

System.out.println(sum); } }

(a)  

26.

阅读下列代码并根据注释完成填空。

public class Test2{

public static void main(String[] args){

                                                (------(1)------)  ; //定义一维整型数组a,元素值为100,200,300

int m=(-----(2)------); //用数组a表示的数组中第2个元素

system.out.println(m);}

}

(a)  

27.

阅读下列代码并根据注释完成填空。

public class Test2{

public static void main(String[] args){

                                                (------(1)------)  ; //定义一维整型数组a,元素值为100,200,300

int m=(-----(2)------); //用数组a表示的数组中第2个元素

system.out.println(m);}

}

(a)  

28.

正整数 n 如果恰好等于它的因子(因子包括 1,不包括 n)之和,这个数就称为 完数,下列代码是求 1000 以内的完数,阅读下列代码并填空。

public class Test3{

public static void main(String[] args){

int sum;

for(int i = 1; i <=1000; i++) {

sum = 0;

for(int j = 1; j <i ; j++){ //循环求因子i的和

if(-----(1)----){ sum = sum + j;}

}

if(------(2)-----){

System.out.println(i); //输出完数

}

}

}

}



(a)  

29.

正整数 n 如果恰好等于它的因子(因子包括 1,不包括 n)之和,这个数就称为 完数,下列代码是求 1000 以内的完数,阅读下列代码并填空。

public class Test3{

public static void main(String[] args){

int sum;

for(int i = 1; i <=1000; i++) {

sum = 0;

for(int j = 1; j <i ; j++){ //循环求因子i的和

if(-----(1)----){ sum = sum + j;}

}

if(------(2)-----){

System.out.println(i); //输出完数

}

}

}

}



(a)