学校jsp题库,爬出来考试用0_0

第1章

选择题

1
2
3
4
5
6
7
8

题库中第1题:
下列哪个是JDK提供的编译器?
A. java.exe
B. javac.exe
C. javap.exe
D. javaw.exe
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第2题:
下列哪个是Java应用程序主类中正确的main方法?
A. public void main (String args[ ])
B. static void main (String args[ ])
C. public static void Main (String args[])
D. public static void main (String args[ ])
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第3题:
下列哪个叙述是正确的?
A. Java语言是20055月Sun公司推出的编程语言,
B. Java语言是19955月IBM司推出的编程语言,
C. Java语言的名字是印度尼西亚一个盛产咖啡的岛名,
D. Java语言的主要贡献者是比尔盖茨。
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第4题:
下列哪个叙述是正确的?
A. Java源文件是由若干个书写形式互相独立的类组成。
B. Java源文件中只能有一个类。
C. 如果源文件中有多个类,那么至少有一个类必须是public
D. Java源文件的扩展名是.txt
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第5题:
对于图1_1的提示,下列哪个解释是正确的?
A. 源文件命名是错误的,
B. 源文件的第4行丢失了语句分号,
C. 源文件的第4行有错误,无法识别system(应该修改为System),
D. 源文件中的E类不是主类。
{correctAnswer='C'}

RioQDP.jpg

1
2
3
4
5
6
7
8

题库中第6题:
1_2给出的四个人物,下列哪个是正确的?
A. 图中左1是java之父:James Gosling,
B. 图中左2是java之父:James Gosling,
C. 图中左3是java之父:James Gosling,
D. 图中左4是java之父:James Gosling。
{correctAnswer='B'}

Riot3j.jpg

1
2
3
4
5
6
7
8

题库中第7题:
下列哪个叙述是正确的?
A. 源文件名字必须是A.java,
B. 如果源文件中有多个类,这些类可以都不是public类,
C. 如果源文件中只有一个类,这个类必须是public类,
D. 如果源文件中只有一个类,这个类必须是主类.
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第8题:
对于下列源文件,哪个叙述是正确的
A. 源文件名字必须是A.java,
B. 源文件有错误,
C. 源文件必须命名为E.java,编译无错误。有两个主类,E和A。程序可以执行主类E也可以执行主类A.
D. 源文件中的E类不是主类。
public class E {
public static void main(String []args) {
System.out.println("ok");
System.out.println("您好");
}
}
class A {
public static void main(String []args) {
System.out.println("ok");
System.out.println("您好");
}
}

{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第9题:
下列哪个叙述是正确的?
A.JDK的全称是Java Development Kit,
B.可以用Microsoft Word 2010 编写Java源文件,
C.不用NetBean或MyEclipse就无法开发Java程序,
D.为了运行Java程序,必须要安装NetBean或MyEclipse。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第10题:
java程序运行入口的main方法(即主类的main方法)的返回类型是什么?
A. void
B. static
C. char
D. int
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第11题:
对于下列源文件,哪个叙诉是正确的?

public class Cat {

public void cry() {

System.out.println("maiomaio");

}

}
A. 源文件的名字必须是Cat.java。
B. 源文件的名字可以是cat.java。
C. 源文件的名字可以任意。
D. Cat类是主类。
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第12题:
对于下列源文件,哪些叙诉是错误的?(多选)

public class Cat {

public void cry() {

System.out.println("maiomaio");

}

}
class E {
public static void main(String args[]) {
System.out.println("ok");
}
}
A. 源文件的名字必须是Cat.java。
B. 源文件的名字可以是E.java。
C. 编译源文件得到Cat.class和E.class两个字节码文件。
D. Cat类是主类,可以java Cat运行程序。
{correctAnswer='BD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第13题:
对于下列源文件,哪个叙诉是错误的?

public class Cat {

public void cry() {

System.out.println("maiomaio");

}

}
class E {
public static void main(String args[]) {
System.out.println("ok");
}
}
A. 源文件的名字必须是Cat.java。
B. 源文件的名字可以是E.java。
C. 编译源文件得到Cat.class和E.class两个字节码文件。
D. E类是主类,java E 来运行程序。
{correctAnswer='B'}

判断题

1
2
3
4

题库中第1题:
Java语言的主要贡献者是James Gosling
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
Java语言是19955月Sun公司推出的编程语言
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
Java语言是19955月IBM司推出的编程语言
{correctAnswer='错误'}
1
2
3
4
5
6
7

题库中第4题:
开发Java应用程序的基本步骤是:
1 编写源文件,
2.编译源文件,
3.运行程序。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
Java源文件是由若干个书写形式互相独立的类组成。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
Java源文件中只能有一个类。
{correctAnswer='错误'}
1
2
3
4

题库中第7题:
如果源文件中有多个类,那么至多有一个类可以是public
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
如果源文件中有多个类,那么必须要有一个类是public
{correctAnswer='错误'}
1
2
3
4

题库中第9题:
如果源文件中有多个类,这些类可以都不是public
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
如果源文件中只有一个类,这个类必须是public
{correctAnswer='错误'}
1
2
3
4

题库中第11题:
如果源文件中只有一个类,这个类必须是主类
{correctAnswer='错误'}
1
2
3
4

题库中第12题:
java源文件中可以没有主类
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
java源文件中可以没有public
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
java源文件的扩展名是.java
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
java源文件的扩展名是.class
{correctAnswer='错误'}
1
2
3
4

题库中第16题:
编译java源文件得到的字节码文件的扩展名是.class
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
java应用程序必须要有主类
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
java应用程序的主类可以不是public
{correctAnswer='正确'}
1
2
3
4

题库中第19题:
java应用程序的主类必须是public
{correctAnswer='错误'}
1
2
3
4

题库中第20题:
必须用文本编辑器编写源文件
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9

题库中第21题:
下列源文件可保存成Dog.java
class Dog {
public void cry() {
System.out.println("wangwang");
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9

题库中第22题:
下列源文件可保存成dog.java
public class Dog {
public void cry() {
System.out.println("wangwang");
}
}
{correctAnswer='错误'}
1
2
3
4
5
6
7
8
9

题库中第23题:
下列源文件必须保存成Dog.java
public class Dog {
public void cry() {
System.out.println("wangwang");
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第24题:
下列源文件可以保存成Dog.java或Cat.java
class Dog {
public void cry() {
System.out.println("wangwang");
}
}
class Cat {
public void cry() {
System.out.println("maiomiao");
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第25题:
下列源文件必须保存成Cat.java
class Dog {
public void cry() {
System.out.println("wangwang");
}
}
public class Cat {
public void cry() {
System.out.println("maiomiao");
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第26题:
下列源文件Dog.java会出现编译错误
public class Dog {
public void cry() {
System.out.println("wangwang");
}
}
public class Cat {
public void cry() {
System.out.println("maiomiao");
}
}
{correctAnswer='正确'}
1
2
3
4

题库中第27题:
如果JDK的安装目录为D:\jdk,也可以临时在命令行编辑path,如图1_1
{correctAnswer='正确'}

Rios5F.jpg

1
2
3
4

题库中第28题:
java编译器位于java安装目录的\bin文件夹中。名字是javac.exe
{correctAnswer='正确'}
1
2
3
4

题库中第29题:
java编译器的名字是java.exe
{correctAnswer='错误'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第30题:
下列源文件People.java中People是主类
class Hello {
public void speak() {
System.out.println("wangwang");
}
}
public class People {
public static void main(String args[]) {
System.out.println("你好");
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第31题:
下列源文件People.java中People是主类
class Hello {
public void speak() {
System.out.println("wangwang");
}
}
public class People {
public void main(String args[]) {
System.out.println("你好");
}
}
{correctAnswer='错误'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第32题:
下列源文件People.java中没有主类,编译,运行效果会如图1_2.
class Hello {
public void speak() {
System.out.println("wangwang");
}
}
public class People {
public void main(String args[]) {
System.out.println("你好");
}
}
{correctAnswer='正确'}

Rio6C4.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第33题:
下列源文件必须保存成Hello.java
并运行主类People,如题1_3.
public class Hello {
public void speak() {
System.out.println("wangwang");
}
}
class People {
public void main(String args[]) {
System.out.println("你好");
}
}
{correctAnswer='正确'}

RiorUU.jpg

1
2
3
4
5

题库中第34题:
出现如图1_4的错误提示,说明程序中语句要求的分号不正确:
编辑源文件时,是在非英文输入法状态下输入的分号,而不是英文输入法下输入的分号
{correctAnswer='正确'}

RioNgs.jpg

1
2
3
4

题库中第35题:
出现如图1_5的错误提示,说明源文件Home.java没有保存在D:\00目录中。
{correctAnswer='正确'}

Rioduq.jpg

1
2
3
4

题库中第36题:
出现如图1_6的错误提示,说明源文件Hello.java中第8行(数行时,包括空行和注释行)中的语句缺失了语句的分号。
{correctAnswer='正确'}

Rio0bV.jpg

1
2
3
4
5
6
7
8

题库中第37题:
使用java解释器运行Hello类:
java Hello
得到提示:“错误: 在类 Hello 中找不到 main 方法, 请将 main 方法定义为:
public static void main(String[] args)
说明Hello不是主类。
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第38题:
下列源文件Hello.java的编程风格属于独行风格
public class Hello {
public void speak() {
System.out.println("wangwang");
}
}
class People {
public static void main(String args[]) {
System.out.println("你好");
}
}
{correctAnswer='错误'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第39题:
下列源文件Hello.java的编程风格属于行尾风格
public class Hello {
public void speak() {
System.out.println("wangwang");
}
}
class People {
public static void main(String args[]) {
System.out.println("你好");
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第40题:
下列源文件的名字必须是Person.java
public class Person {
void speakHello() {
System.out.print("您好,很高兴认识您");
System.out.println(" nice to meet you");
}
}
class Xiti {
public static void main(String args[]) {
Person zhang = new Person();
zhang.speakHello();
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第41题:
编译下列源文件的Person.java将得到2个字节码文件:Person.class和Xiti.class.
public class Person {
void speakHello() {
System.out.print("您好,很高兴认识您");
System.out.println(" nice to meet you");
}
}
class Xiti {
public static void main(String args[]) {
Person zhang = new Person();
zhang.speakHello();
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第42题:
下列源文件Person.java编译通过后,如果用解释器java如下运行程序
java xiti
将得到如图1_7所示的提示,因为主类的名字不是xiti,而是Xiti。
public class Person {
void speakHello() {
System.out.print("您好,很高兴认识您");
System.out.println(" nice to meet you");
}
}
class Xiti {
public static void main(String args[]) {
Person zhang = new Person();
zhang.speakHello();
}
}
{correctAnswer='正确'}

RiowD0.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第43题:
下列源文件Person.java编译通过后,如果用解释器java如下运行程序
java Person
将得到如图1_8所示的提示,因为主类的名字不是Person,而是Xiti。
public class Person {
void speakHello() {
System.out.print("您好,很高兴认识您");
System.out.println(" nice to meet you");
}
}
class Xiti {
public static void main(String args[]) {
Person zhang = new Person();
zhang.speakHello();
}
}
{correctAnswer='正确'}

RioDET.jpg

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
public class Example //A
{
public static void main(String args[]) //B
{
System.out.println("ok"); //C
System.out.println("hello");
system.out.println("您好"); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
Public class Example //A
{
public static void main(String args[]) //B
{
System.out.println("ok"); //C
System.out.println("hello");
System.out.println("您好"); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
public class Example //A
{
public static void main(string args[]) //B
{
System.out.println("ok"); //C
System.out.println("hello");
System.out.println("您好"); //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
public class Example //A
{
public static void main(String args[]) //B
{
System.out.println("ok"); //C
System.out.println("hello");
System.out.println("您好”); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
public class Example //A
{
public static void main(String args[]) //B
{
System.out.println("ok") //C
System.out.println("hello");
System.out.println("您好"); //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第6题:
下列ABCD注释标注的哪行代码有错误?
public class Example //A
{
public void main(String args[]) //B
{
System.out.println("ok"); //C
System.out.println("hello");
System.out.println("您好"]; //D
}
}
{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
public class Example {
public static void main(String args[]) {
System.out.println("hello"); //【代码】

}
}
{correctAnswer='hello'}
1
2
3
4
5
6
7
8
9

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
System.out.println(100); //【代码】
}
}
{correctAnswer='100'}

第2章

选择题

1
2
3
4
5
6
7
8

题库中第1题:
下列哪个类型声明的变量可以取truefalse两个值?
A. byte
B. boolean
C. char
D. double
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第2题:
下列哪项字符序列可以做为标识符?
A. true
B. default
C. _int
D. good-class
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第3题:
下列哪一项是正确的float变量的声明?
A. float foo = 1;
B. float foo = 1.0;
C. float foo = 2e1;
D. float foo = 2.02;
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第4题:
下列哪一项是正确的float变量的声明?
A. float foo = 1e2;
B. float foo = 3.14;
C. float foo = 3.03d;
D. float foo = 0x0123;
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第5题:
下列哪一项叙述是正确的?
A. char型字符在Unicode表中的位置范围是032767
B. char型字符在Unicode表中的位置范围是065535
C. char型字符在Unicode表中的位置范围是065536
D. char型字符在Unicode表中的位置范围是-3276832767
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第6题:
以下哪一项是正确的char型变量的声明?
A. char ch = "R";
B. char ch = '\\'
C. char ch = 'ABCD';
D. char ch = "ABCD";
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第7题:
以下哪一项是错误的char型变量的声明?
A. char ch = '\ucafe';
B. char ch = '\u1010'
C. char ch = '\t';
D. char ch = '\t\n';
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第8题:
对于int a[] = new int[3];下列哪个叙述是错误的?
A. a.length的值是3
B. a[1]的值是1
C. a[0]的值是0
D. a[a.length-1]的值等于a[2]的值。

{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第9题:
以下哪一项是错误的float变量的声明?
A. float a = 1.19;
B. float b = 520;
C. float c = 'a';
D. float d = 1.0f;
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第10题:
以下哪一项是错误的float变量的声明?
A. float a = 2e3;
B. float b = 520;
C. float c = '你';
D. float d = 3.14F;
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第11题:
以下哪一项是正确的float常量?
A. 15.3;
B. 3.14E2;
C. 67F;
D. 10d;
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第12题:
以下哪一项是Java语言的关键字?
A. Class
B. int
C. Float
D. main
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第13题:
以下哪种类型变量占用的内存最少?
A. short
B. int
C. float
D. byte
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第14题:
以下哪种类型变量占用的内存最少?
A. char
B. int
C. double
D. long
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第15题:
以下哪种类型变量占用的内存最多?
A. int
B. float
C. double
D. char
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第16题:
以下哪个是错误的数组声明?
A. short [] a;
B. int a[5];
C. float []a[];
D. byte [][]a
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10

题库中第17题:
对于int [][] a = {{1,2},{1,2,3},{1,2,3,4}};
下列哪个叙述是错误的?
A. a.length的值是3
B. a[2].length的值是4
C. a[0][1]的值是1
D. a[2][0]的值是1

{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第18题:
下列哪项是Java语言规定的关键字?
A. run
B. import
C. Int
D. implement
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第19题:
下列哪项是Java语言规定的关键字?
A. NULL
B. sizeof
C. friend
D. extends
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第20题:
下列哪项正确表达了int型变量的取值范围?
A. 取决于编译器
B. -231231-1
C. -231-1231
D. -216216-1
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第21题:
char型变量的取值范围是下列哪一项?
A. 0216
B. 0216-1
C. -215215-1
D. 0215-1
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第22题:
对于下列Test.java代码,下列哪个叙述是正确的?
public class Test{
public static void main(String args[]){
int arr[] = new int[10];
System.out.println(arr[1]);
}
}
A. 产生编译错误。
B. 输出null
C. 编译正确,发生运行异常。
D. 输出:0
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第23题:
对于下列Test.java代码,下列哪个叙述是正确的?
public class Test{
public static void main(String args[]){
int arr[] ;
System.out.println(arr[1]);
}
}
A. 产生如图2_1所示编译错误。
B. 输出null
C. 编译正确,发生运行异常。
D. 输出:0
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第24题:
对于下列E.java代码,下列哪个叙述是正确的?
public class E {
public static void main(String args[]) {
int [] a = {1,2,3,4};
System.out.println(a[4]);
}
}
A. 有编译错误。
B. 输出4
C. 编译正确,发生运行异常ArrayIndexOutOfBoundsException: 4
D. 输出:3
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第25题:
对于下列E.java代码,下列哪个叙述是正确的?
public class E {
public static void main(String args[]) {
int [][] a = {{1,2,3,4},{100,200,300},{7,8}};
System.out.println(a[3][0]);
}
}
A. 有编译错误。
B. 输出7
C. 编译正确,发生运行异常ArrayIndexOutOfBoundsException: 3
D. 输出:100
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第26题:
哪些叙述是正确的?(多选)
A. char ch = '\t';是正确的char变量声明。
B. char ch ='你';是正确的char变量声明。
C. char ch ='\u000M';是正确的char变量声明。
D. char ch ='\0';是正确的char变量声明。
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8

题库中第27题:
哪个叙述是错误的?
A. char ch = '\t';是正确的char变量声明。
B. char ch ='你';是正确的char变量声明。
C. char ch ='\u000M';是正确的char变量声明。
D. char ch ='\0';是正确的char变量声明。
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第28题:
哪个叙述是正确的?
A. float height = 3.5F;是正确的float变量声明。
B. main是java语言规定的关键字。
C. boolean yes = 1;是正确的boolean变量声明。
D. byte amount = 128;是正确的byte型变量声明。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第29题:
哪些叙述是错误的?(多选)
A. float height = 3.5F;是正确的float变量声明。
B. main是java语言规定的关键字。
C. boolean yes = 1;是正确的boolean变量声明。
D. byte amount = 128;是正确的byte型变量声明。
{correctAnswer='BCD'}
1
2
3
4
5
6
7
8

题库中第30题:
哪些叙述是正确的?(多选)
A. int [] a,b[];是声明了1int型一维数组a和1int型二维数组b。
B. float a[20];是正确的数组声明。
C. boolean yes = false;是正确的boolean变量声明。
D. 1e22.05E2都是double型常量。
{correctAnswer='ACD'}
1
2
3
4
5
6
7
8

题库中第31题:
哪个叙述是错误的?
A. int [] a,b[];是声明了1int型一维数组a和1int型二维数组b。
B. float a[20];是正确的数组声明。
C. boolean yes = false;是正确的boolean变量声明。
D. 1e22.05E2都是double型常量。
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第32题:
哪个叙述是错误的?
A. System是关键字。
B. _class可以作为标识符。
C. char型字符在Unicode表中的位置范围是065535
D. 对于int a[] = new int[3];a.length的值是3
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第33题:
哪个叙述是错误的?
A. 对于int a[][] = new int[6][4];a.length的值是6
B. 对于int a[][] = new int[2][9];a.length的值是2,a[0].length,a[1].length的值都是9
C. 对于int [] a = new int[3];a[0],a[1],a[2]的值都是0
D. float height = 1eF;是正确的float变量声明。
{correctAnswer='B'}

判断题

1
2
3
4

题库中第1题:
标识符的第一个字符可以是数字。
{correctAnswer='错误'}
1
2
3
4

题库中第2题:
标识符的长度最多为30个字符长度。
{correctAnswer='错误'}
1
2
3
4

题库中第3题:
*号可以出现在标识符中。
{correctAnswer='错误'}
1
2
3
4

题库中第4题:
标识符不能是truefalsenull(尽管truefalsenull不是Java关键字)。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
汉字可以出现在标识符中。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
Bird和bird是相同的标识符。
{correctAnswer='错误'}
1
2
3
4

题库中第7题:
java是关键字。
{correctAnswer='错误'}
1
2
3
4

题库中第8题:
System是关键字。
{correctAnswer='错误'}
1
2
3
4

题库中第9题:
3.14float型常量。
{correctAnswer='错误'}
1
2
3
4

题库中第10题:
3.14F0.618f都是float型常量。
{correctAnswer='正确'}
1
2
3
4

题库中第11题:
3.140.618d都是double型常量。
{correctAnswer='正确'}
1
2
3
4

题库中第12题:
2e53.14E2都是double型常量.
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
3e10ffloat型常量。
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
int []a;和int a[];都是正确的声明了一个一维数组a。
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
int [] a,b;是声明了2int型一维数组a和b。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
int a[],b;是声明了一个int型一维数组a和一个int型变量b。
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
int a[],b[];是声明了2int型一维数组a和b。
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
int [] a,b[];是声明了1int型一维数组a和1int型二维数组b。
{correctAnswer='正确'}
1
2
3
4

题库中第19题:
float a[20];是错误的数组声明。
{correctAnswer='正确'}
1
2
3
4

题库中第20题:
boolean yes = false;是正确的boolean变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第21题:
int a[20];是正确的数组声明。
{correctAnswer='错误'}
1
2
3
4

题库中第22题:
good-class可以作为标识符。
{correctAnswer='错误'}
1
2
3
4

题库中第23题:
_int可以作为标识符。
{correctAnswer='正确'}
1
2
3
4

题库中第24题:
float height = 1.0;是正确的float变量声明。
{correctAnswer='错误'}
1
2
3
4

题库中第25题:
boolean yes = TRUE;是正确的boolean变量声明。
{correctAnswer='错误'}
1
2
3
4

题库中第26题:
float foo = 0x0123;是正确的float变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第27题:
int OK = 3.19;是正确的int型变量声明。
{correctAnswer='错误'}
1
2
3
4

题库中第28题:
float area = 1e1;是错误的float变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第29题:
double width = 1e1;是正确的double变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第30题:
float height = 1.0f;是正确的float变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第31题:
char ch = '\\';是正确的char变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第32题:
char ch = '\u0061';是正确的char变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第33题:
char ch = 97;是错误的char变量声明。
{correctAnswer='错误'}
1
2
3
4

题库中第34题:
char型字符在Unicode表中的位置范围是065535
{correctAnswer='正确'}
1
2
3
4

题库中第35题:
char型字符在Unicode表中的位置范围是-3276832767
{correctAnswer='错误'}
1
2
3
4

题库中第36题:
对于int a[] = new int[3];a.length的值是3
{correctAnswer='正确'}
1
2
3
4

题库中第37题:
对于int [] a = new int[3];a[0],a[1],a[2]的值都是0
{correctAnswer='正确'}
1
2
3
4

题库中第38题:
对于int a[][] = new int[6][4];a.length的值是6
{correctAnswer='正确'}
1
2
3
4

题库中第39题:
对于int a[][] = new int[2][9];a.length的值是2,a[0].length,a[1].length的值都是9
{correctAnswer='正确'}
1
2
3
4

题库中第40题:
对于 int [][] a ={{1,2,3},{4,5,6,7}};a[0].length的值是3,a[1].length的值是4
{correctAnswer='正确'}
1
2
3
4

题库中第41题:
char ch = '\n';是正确的char变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第42题:
char ch ="a";是正确的char变量声明。
{correctAnswer='错误'}
1
2
3
4

题库中第43题:
char ch ='abcd';是错误的char变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第44题:
char ch ='\0';是正确的char变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第45题:
char ch ='\u777f;是正确的char变量声明。
{correctAnswer='正确'}
1
2
3
4

题库中第46题:
char ch ='\u777g;是正确的char变量声明。
{correctAnswer='错误'}
1
2
3
4

题库中第47题:
main是java语言规定的关键字。
{correctAnswer='错误'}
1
2
3
4

题库中第48题:
boolean yes = 1;是正确的boolean变量声明。
{correctAnswer='错误'}
1
2
3
4

题库中第49题:
byte amount = 128;是正确的byte型变量声明。
{correctAnswer='错误'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第50题:
下列源文件Test.java代码可以通过编译,即没有编译错误,但运行时触发异常:
ArrayIndexOutOfBoundsException: 3
Test.java:
public class Test {
public static void main(String args[]){
int [] a = {1,2,3};
System.out.println(a[3]);
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第51题:
下列源文件Test.java代码可以通过编译,即没有编译错误,但运行时触发异常:
ArrayIndexOutOfBoundsException: 2
Test.java:
public class Test {
public static void main(String args[]){
int [][] a = {{1,2,3},{100,200}};
System.out.println(a[2][0]);
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第52题:
下列源文件Test.java代码可以通过编译,即没有编译错误,但运行时触发异常:
ArrayIndexOutOfBoundsException: 0
Test.java:
public class Test {
public static void main(String args[]){
int [][] a = {{1,2,3},{}};
System.out.println(a[1][0]);
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第53题:
下列源文件Test.java代码可以通过编译,即没有编译错误,但运行时触发异常:
ArrayIndexOutOfBoundsException: 2
Test.java:
public class Test {
public static void main(String args[]){
int [][] a = {{1,2,3},{5,6}};
System.out.println(a[1][2]);
}
}
{correctAnswer='正确'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第54题:
下列源文件Test.java代码可以通过编译,即没有编译错误,但运行时触发异常:
ArrayIndexOutOfBoundsException: 3
Test.java:
public class Test {
public static void main(String args[]){
int [][] a = {{1,2,3},{5,6}};
System.out.println(a[0][3]);
}
}
{correctAnswer='正确'}
1
2
3
4

题库中第55题:
public和class都是java语言规定的关键字。
{correctAnswer='正确'}
1
2
3
4

题库中第56题:
e1是101次幂(1次方)。
{correctAnswer='错误'}
1
2
3
4

题库中第57题:
1e1101次幂(1次方)。
{correctAnswer='正确'}
1
2
3
4

题库中第58题:
1e是101次幂(1次方)。
{correctAnswer='错误'}
1
2
3
4

题库中第59题:
1e2int型常量。
{correctAnswer='错误'}
1
2
3
4

题库中第60题:
1e2double型常量。
{correctAnswer='正确'}
1
2
3
4

题库中第61题:
1e2ffloat型常量。
{correctAnswer='正确'}
1
2
3
4

题库中第62题:
把一个int型常量赋值给一个byteshortchar型变量时,不可超出这些变量的取值范围,否则必须进行类型转换运算
{correctAnswer='正确'}
1
2
3
4

题库中第63题:
标识符由字母、下划线、美元符号和数字组成,并且第一个字符不能是数字字符。
{correctAnswer='正确'}
1
2
3
4

题库中第64题:
Java语言有8种基本数据类型:booleanbyteshortintlongfloatdoublechar
{correctAnswer='正确'}
1
2
3
4

题库中第65题:
数组是相同类型的数据元素按顺序组成的一种复合数据类型,因此两个相同类型的数组如果具有相同的引用,它们就有完全相同的元素。
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
char c ='\uabcg'; //A
byte b = 127; //B
int x = 100; //C
float f = 3.14F; //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
char c ='\uabcf'; //A
byte b = 127; //B
int public = 100; //C
float f = 3.14F; //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
char c ='a'; //A
byte b = 128; //B
int height = 100; //C
float f = 3.14F; //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
char c =65536; //A
byte b = 127; //B
int height = 100; //C
float f = 3.14F; //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
char c =65535; //A
byte b = 127; //B
int height = 100; //C
float f = 1e4; //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第6题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
int x = 8;
byte b = 127;
b = x; //A
x = 'a'; //B
long y= b; //C
float z=(int)6.89 ; //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第7题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
char c =65535; //A
byte b = 127; //B
int height = 100; //C
float f = 3.14; //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第8题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
int m = 'a'; //A
char ch = m; //B
ch = 97; //C
double t = 0.1; //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第9题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
int m = 'a'; //A
unsigned char x = 'm'; //B
ch = 97; //C
double t = 0.1; //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第10题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main(String args[]){
char c =65535; //A
byte b = 127; //B
unsigned int y = 200; //C
float f = 3.14f; //D
}
}
{correctAnswer='C'}

读程题

1
2
3
4
5
6
7
8
9

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
System.out.println(Byte.MAX_VALUE); //【代码】
}
}
{correctAnswer='127'}
1
2
3
4
5
6
7
8
9

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
System.out.println(Byte.MIN_VALUE); //【代码】
}
}
{correctAnswer='-128'}
1
2
3
4
5
6
7
8
9

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
System.out.println((int)'a'); //【代码】
}
}
{correctAnswer='97'}
1
2
3
4
5
6
7
8
9

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
System.out.println((char)65); //【代码】
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int m = 100;
System.out.println(m+"100"); //【代码】
}
}
{correctAnswer='100100'}
1
2
3
4
5
6
7
8
9
10

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int m =100;
System.out.println(m+100); //【代码】
}
}
{correctAnswer='200'}
1
2
3
4
5
6
7
8
9
10

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [] a ={1,2,3,4,5,6};
System.out.println(a.length+"hello"+a[5]); //【代码】
}
}
{correctAnswer='6hello6'}
1
2
3
4
5
6
7
8
9
10

题库中第8题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a ={{0,1,2,3,4},{5,6},{8,9,10}};
System.out.println(a.length+"java"+a[2][0]); //【代码】
}
}
{correctAnswer='3java8'}
1
2
3
4
5
6
7
8
9
10

题库中第9题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a ={{0,1,2,99,4},{5,6},{8,9,10}};
System.out.println(a[1].length+"java"+a[0][3]); //【代码】
}
}
{correctAnswer='2java99'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第10题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int a[] = {1,2,3,4};
int b[] = {100,200,300};
a = b;
System.out.println(a[1]); //【代码】
}
}
{correctAnswer='200'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第11题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int a[] = {1,2,3,4};
int b[] = {100,200,300};
b = a;
System.out.println(b[3]); //【代码】
}
}
{correctAnswer='4'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第12题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int a[] = {1,2,3,4};
int b[] = {100,200,300};
b = a;
System.out.println(b.length); //【代码】
}
}
{correctAnswer='4'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第13题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int a[] = {1,2,3,4};
int b[] = {100,200,300};
a = b;
System.out.println(a.length); //【代码】
}
}
{correctAnswer='3'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第14题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a = {{1,2,3,4},{5,6},{7,8,9}};
int b[] = {100,200,300};
b = a[0];
System.out.println(b[0]); //【代码】
}
}
{correctAnswer='1'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第15题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a = {{1,2,3,4},{5,6},{7,8,9}};
int b[] = {100,200,300};
a[1] = b;
System.out.println(a[1][2]); //【代码】
}
}
{correctAnswer='300'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第16题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a = {{1,2,3,4},{5,6},{7,8,9}};
int b[] = {100,200,300};
a[2] = b;
System.out.println(a[2][0]); //【代码】
}
}
{correctAnswer='100'}
1
2
3
4
5
6
7
8
9
10
11

题库中第17题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a = {{1,2,3,4},{5,6},{7,8,9}};
a[2] = a[0];
System.out.println(a[2][0]); //【代码】
}
}
{correctAnswer='1'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第18题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a = {{0,1,2,3,4},{5,6},{7,8,9}};
int [] b ={100,200,300};
b = a[0];
System.out.println(b.length+"java"+b[0]); //【代码】
}
}
{correctAnswer='5java0'}
1
2
3
4
5
6
7
8
9
10
11

题库中第19题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
char c = '好';
int m = (int)c;
System.out.println("你"+(char)m); //【代码】
}
}
{correctAnswer='你好'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第20题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a = {{0,1,2,3,4},{5,6},{7,8,9}};
int [] b ={100,200,300};
a[0] = b;
int m = a[0][2]+b[2];
System.out.println(m); //【代码】
}
}
{correctAnswer='600'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第21题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a = {{0,1,2,3,4},{5,6},{7,8,9}};
int [] b ={100,200,300};
a[0] = b;
System.out.println(a[0].length+"java"+a[0][0]); //【代码】
}
}
{correctAnswer='3java100'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第22题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]){
int [][] a = {{0,1,2,3,4},{5,6},{7,8,9}};
int [] b ={100,200,300};
a[0][0] = b[2];
System.out.println(a[0].length+"java"+a[0][0]); //【代码】
}
}
{correctAnswer='5java300'}

第3章

选择题

1
2
3
4
5
6
7
8
9

题库中第1题:
下列哪个叙述是正确的?
A. 5.0/2+10的结果是double型数据。
B.(int)5.8+1.0的结果是int型数据。
C.'苹'+ '果'的结果是char型数据。
D.(short)10+'a'的结果是short型数据。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第2题:
用下列哪个代码替换程序标注的【代码】会导致编译错误?
public class E {
public static void main (String args[ ]) {
int m=10,n=0;
while(【代码】) {
n++;
}
}
}
A.m-->0
B.m++>0
C.m = 0
D.m>100&&true
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第3题:
用下列哪个代码替换程序标注的【代码】会导致编译错误?
public class E {
public static void main (String args[ ]) {
int m=10,n=0;
if(【代码】) {
n++;
}
}
}
A.m-->0
B.m++>0
C.m = 0
D.m>100&&true
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第4题:
用下列哪个替换程序中的【代码】导致如图3_1所提示的错误。
public class Test {
public static void main (String args[ ]) {
byte m = 1;
byte n = 1+【代码】;
}
}
A.'a'
B.126
C.m
D.'A'
注解:允许把不超出byte的取值范围的int常量赋值给byte变量。但是注意,编译器在编译时并不计算1+m中变量m中的值,只是编译出1+m表达式的值是int型数据。有关知识点见教材3.1.3节。
{correctAnswer='C'}

RiTMRJ.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第5题:
用下列哪个替换程序中的【代码】导致如图3_2所提示的错误。
public class Test {
public static void main (String args[ ]) {
int x = 0;
【代码】
}
}
A.short t = 12+'a';
B.char c ='a'+1;
C.char m ='a'+x;
D.byte n ='a'+1;
注解:允许把不超出byte,char,short的取值范围的int常量赋值给相应的变量。但是注意,编译器在编译时并不计算'a'+x中变量x中的值,只是编译出'a'+x表达式的值是int型数据。有关知识点见教材3.1.3节。
{correctAnswer='C'}

RiTQz9.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第6题:
以下哪一项是下列代码的执行输出结果?
public class Test {
public static void main (String args[ ]) {
int m =10,n;
n = m++;
n = --m;
System.out.printf("%d,%d",m,n);
}
}

A. 11,10
B. 10,10
C. 10,11
D. 11,11
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第7题:
对于下列Test.java下列哪个叙述是正确的?
public class Test {
public static void main (String args[ ]) {
int m = 10, n = 20;
if(n>m)
System.out.print("hello");
else
System.out.print("ok");
System.out.print("你好");
}
}
A. 程序输出的结果是hello你好
B. 程序的输出结果是hello
C. 程序输出的结果是ok
D. 程序输出的结果是你好
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第8题:
对于下列Test.java下列哪个叙述是正确的?
public class Test {
public static void main (String args[ ]) {
int m = 10, n = 20;
if(n>m)
System.out.print("hello");
System.out.print("你好");
else
System.out.print("ok");
System.out.print("yes");
}
}
A. 出现编译错误。
B. 程序的输出结果是hello你好
C. 程序输出的结果是ok
D. 程序输出的结果是okyes
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第9题:
对于下列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. 出现编译错误。
B. 程序的输出结果是hello你好
C. 程序输出的结果是ok
D. 程序输出的结果是okyes
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第10题:
对于下列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. 出现编译错误。
B. 程序的输出结果是hello你好
C. 程序输出的结果是ok
D. 程序输出的结果是okyes
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第11题:
对于下列Test.java下列哪个叙述是正确的?
public class Test {
public static void main (String args[ ]) {
int m =100;
if(m = 100){
System.out.print("hello");
System.out.print("你好");
}
else {
System.out.print("ok");
System.out.print("yes");
}
}
}

A. 出现编译错误。
B. 程序的输出结果是hello你好
C. 程序输出的结果是ok
D. 程序输出的结果是okyes
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第12题:
对于下列Test.java下列哪个叙述是正确的?
public class Test {
public static void main (String args[ ]) {
double m = 0.4;
double n = 0.4F;
if(m == n){
System.out.printf("%s","您好");
}
else {
System.out.printf("%s","hello");
}
}
}

A. 出现编译错误。
B. 程序的输出结果是您好。
C. 程序输出的结果是hello。
D. 程序没有输出任何结果。
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第13题:
对于下列Test.java下列哪个叙述是正确的?
public class Test {
public static void main (String args[ ]) {
int m =100;
if(m == 100){
System.out.print("hello");
System.out.print("你好");
}
else {
System.out.print("ok");
System.out.print("yes");
}
}
}

A. 出现编译错误。
B. 程序的输出结果是hello你好
C. 程序输出的结果是ok
D. 程序输出的结果是okyes
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第14题:
下列哪个叙述是正确的??
A. 'a'+10的结果是int型数据。
B.(int)5.8+2e1的结果是int型数据。
C.'苹'+ '果'的结果是char型数据。
D.(byte)3.14+1的结果是byte型数据。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第15题:
对于int n=6789;,表达式的值为7的是:

A. n%10
B. n/10%10
C. n/100%10
D. n/1000%10
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第16题:
对于int n=789;,表达式的值为8的是:

A. n%10
B. n/10
C. n/100%10
D.(n-n/100*100)/10
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第17题:
用下列哪个代码替换程序标注的【代码】会导致编译错误?
public class E {
public static void main (String args[ ]) {
for(int m =-10;【代码】;m++) {
m++;
}
}
}
A.m-- > 0
B.m++ >0
C.m = 0
D.m < 100
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第18题:
用下列哪个代码替换程序标注的【代码】会导致编译错误?
public class Test {
public static void main (String args[ ]) {
int m = 0;
if(【代码】){
System.out.println("条件表达式必须是bookean");
}
}
}
A.m-- > 0
B.++m >0
C.m = 0
D.m != 0
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第19题:
用下列哪个代码替换程序标注的【代码】会使得程序输出您好。
public class Test {
public static void main (String args[ ]) {
int m = 0;
if(【代码】){
System.out.println("您好");
}
else {
System.out.println("hello");
}
}
}
A.m-- > 0
B.++m >0
C.m++ > 0
D.--m > 0
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第20题:
用下列哪个代码替换程序标注的【代码】会使得程序输出hello。
public class Test {
public static void main (String args[ ]) {
int m = 0;
if(【代码】){
System.out.println("您好");
}
else {
System.out.println("hello");
}
}
}
A.m-- <= 0
B.++m > 0
C.m++ > 0
D.--m < 0
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第21题:
下列哪些叙述是正确的?(多选)
A. 表达式5.0/2+10的结果是double型数据:12.5
B. 表达式5/2的结果是2
C. 表达式10>20-17的结果是1
D. 表达式5>1的结果是true

{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9

题库中第22题:
下列哪个叙述是错误的?
A. 表达式5.0/2+10的结果是double型数据:12.5
B. 表达式5/2的结果是2
C. 表达式10>20-17的结果是1
D. 表达式5>1的结果是true

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第23题:
下列哪个叙述是错误的?
A. 逻辑运算符的运算结果是int型数据。
B. 关系运算符的运算结果是boolean型数据。
C. 逻辑运算符的运算结果是boolean型数据。
D. 逻辑运算符的操作元必须是boolean型数据。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第24题:
下列哪个叙述是错误的?
A. while(表达式)...语句中的“表达式”的值必须是boolean型数据。。
B. for(表达式1; 表达式2; 表达式3)...语句中的“表达式2”的值必须是boolean型数据。
C. if(表达式)...语句中的“表达式”的值必须是boolean型数据。
D. switch语句中必须要有default选项。

{correctAnswer='D'}

判断题

1
2
3
4

题库中第1题:
表达式5.0/2+10的结果是double型数据:12.5
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
表达式5/2的结果是2
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
表达式10>20-17的结果是1
{correctAnswer='错误'}
1
2
3
4

题库中第4题:
表达式5>1的结果是true
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
表达式2>8&&9>2的结果为false
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
表达式2>8||9>2的结果为1
{correctAnswer='错误'}
1
2
3
4

题库中第7题:
关系运算符的运算结果是int型数据。
{correctAnswer='错误'}
1
2
3
4

题库中第8题:
逻辑运算符的运算结果是int型数据。
{correctAnswer='错误'}
1
2
3
4

题库中第9题:
关系运算符的运算结果是boolean型数据。
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
逻辑运算符的运算结果是boolean型数据。
{correctAnswer='正确'}
1
2
3
4

题库中第11题:
逻辑运算符的操作元必须是boolean型数据。
{correctAnswer='正确'}
1
2
3
4

题库中第12题:
逻辑运算符的操作元必须是boolean型数据。
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
12 = 12 是非法的表达式。
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
if语句中的条件表达式的值可以是int型数据。
{correctAnswer='错误'}
1
2
3
4

题库中第15题:
while(表达式)...语句中的“表达式”的值必须是boolean型数据。。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
for(表达式1; 表达式2; 表达式3)...语句中的“表达式2”的值必须是boolean型数据。
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
if(表达式)...语句中的“表达式”的值必须是boolean型数据。
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
switch语句中必须要有default选项。
{correctAnswer='错误'}
1
2
3
4

题库中第19题:
while语句的循环体中,执行break语句的效果是结束while语句。
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
byte b = 'a'; //A
int n =100;
char c = 65; //B
b = b; //C
b = b+1; //D
}
}
注解:允许把不超出byte的取值范围int常量赋值给byte变量。但是注意,编译器在编译时并不计算b+1中变量b中的值,只是编译出b+1表达式的值是int型数据(注意java认为1int型常量)。有关知识点见教材3.1.3节。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
char ch = '花'; //A
byte n = -100;
ch = ch-ch; //B
n = n; //C
n = 127; //D
}
}
注解:允许把不超出char的取值范围的int常量赋值给char变量。但是注意,编译器在编译时并不计算char-char中变量char中的值,只是编译出char-char表达式的值是int型数据。有关知识点见教材3.1.3节。
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
byte b = 32; //A
int n =100;
char c = 'A'+b; //B
b = b; //C
int m = b+1; //D
}
}
注解:允许把不超出byte,short,char的取值范围int常量赋值给相应变量。但是注意,编译器在编译时并不计算'A'+b中变量b中的值,只是编译出该表达式的值是int型数据。有关知识点见教材3.1.3节。
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
byte b = 32; //A
char c = 'A'; //B
byte n = (byte)c; //C
short m = b+1; //D
}
}
注解:允许把不超出byte,short,char的取值范围int常量赋值给相应变量。但是注意,编译器在编译时并不计算b+1中变量b中的值,只是编译出该表达式的值是int型数据。有关知识点见教材3.1.3节。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
int m = 12;
int n = 12;
int number = 100+'w'; //A
switch(number) {
case 12: n++; //B
case 100:n--; //C
break;
case n : m++; //D
}
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第6题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
int m = 12;
int n = 12;
long number = 100; //A
switch(number) //B
{
case 12: n++;
case 100:n--; //C
break;
case 12+9 : m++; //D
}
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第7题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
int m =100,n =10;
if(100 = m) //A
{
System.out.println("No");
}
else if(10 == n ) //B
{
System.out.println("逻辑相等常量在前是好习惯");
}
else if(100 == m ) //C
{
System.out.println("逻辑相等常量在前是好习惯");
}
else if(m != n) //D
{
System.out.println("ok");
}
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第8题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
int m =1000;
while(m > 100) //A
{
m = m--; //B
if (m == 600){ //C
break;
m++; //D
}
}
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第9题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
int m =1000;
while(m > 100) //A
{
m = m--; //B
if (m == 600){ //C
continue;
m++; //D
}
}
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第10题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
int a[] = {1,2,3,4};//A
for(int n = 0;n < a.length; n++) //B
{
System.out.println(a[n]);
}
for(int i:a) //C
{
System.out.println(i);
}
int m = 0;
for(m:a) //D
{
System.out.println(m);
}
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第11题:
下列ABCD注释标注的哪行代码有错误?
public class Test {
public static void main (String args[ ]) {
byte b =7;
b = 7+120; //A
b = b; //B
b = b+120; //C
b += 120; //D
}
}
注解:允许把不超出byte,short,char的取值范围int常量赋值给相应变量。但是注意,编译器在编译时并不计算120+b中变量b中的值,只是编译出该表达式的值是int型数据。有关知识点见教材3.1.3节。
需要注意的是,对于 +=.*=,/=,-= 缩略运算符,编译器自动将赋值符号右侧的表达式的值转换成左边变量所要求的类型,例如b += 120等同于
b =(byet)(b+120)
{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
byte b =(byte)-129;
System.out.println(b);//【代码】
}
}
{correctAnswer='127'}
1
2
3
4
5
6
7
8
9
10

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int b =(int)3.14;
System.out.println(b);//【代码】
}
}
{correctAnswer='3'}
1
2
3
4
5
6
7
8
9
10

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
char ch =(char)(65536+97);
System.out.println(ch);//【代码】
}
}
{correctAnswer='a'}
1
2
3
4
5
6
7
8
9
10

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
char ch =(char)(65536+65);
System.out.println(ch);//【代码】
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m = 100;
m = m^m;
System.out.println(m);//【代码】
}
}
{correctAnswer='0'}
1
2
3
4
5
6
7
8
9
10
11

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m = 5;
m = m<<2;
System.out.println(m);//【代码】
}
}
{correctAnswer='20'}
1
2
3
4
5
6
7
8
9
10
11

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m = 24;
m = m>>3;
System.out.println(m);//【代码】
}
}
{correctAnswer='3'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第8题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m = 28,n =10;
m = m^n;
m = m^n;
System.out.println(m);//【代码】
}
}
{correctAnswer='28'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第9题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
boolean boo =false;
int x = -1;
boo = ((x=10)>9)&&((x=100)>99);
System.out.println(boo+"hello"+x); //【代码】
}
}
{correctAnswer='truehello100'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第10题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
boolean boo =false;
int x = -1;
boo = ((x=10)<9)&((x=100)>99);
System.out.println(boo+"hello"+x); //【代码】
}
}
{correctAnswer='falsehello100'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第11题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
boolean boo =false;
int x = -1;
boo = ((x=10)<9)&&((x=100)>99);
System.out.println(boo+"hello"+x); //【代码】
}
}
{correctAnswer='falsehello10'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第12题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
boolean boo =false;
int x = -1;
boo = ((x=10)>9)||((x=100)>99);
System.out.println(boo+"hello"+x); //【代码】
}
}
{correctAnswer='truehello10'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第13题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
boolean boo =false;
int x = -1;
boo = ((x=10)<9)||((x=100)>99);
System.out.println(boo+"hello"+x); //【代码】
}
}
{correctAnswer='truehello100'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第14题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
boolean boo =false;
int x = -1;
boo = ((x=10)>9)|((x=100)>99);
System.out.println(boo+"hello"+x); //【代码】
}
}
{correctAnswer='truehello100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第15题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
char ch1 = 'A',ch2 ='B',ch3 = 'N';
char t = '\0';
if(ch2 > ch1) {
t = ch1;
ch1 = ch2;
ch2 = t;
}
if(ch3 > ch1) {
t = ch1;
ch1 = ch3;
ch3 = t;
}
if(ch3 > ch2) {
t = ch2;
ch2 = ch3;
ch3 = t;
}
System.out.printf("%c%c%c",ch1,ch2,ch3); //【代码】
}
}
{correctAnswer='NBA'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第16题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m =100,n =10;
if(m > n) {
n = 100;
m = 10;
}
else
n = -100;
m = -99;
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='-99:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第17题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m =100,n =10;
if(m > n) {
n = 100;
m = 10;
}
else {
n = -100;
m = -99;
}
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='10:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第18题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m = 0;
char ch ='A';
switch(ch) {
case 9 :
case 'a' : m = m+1;;
break;
case 'A' : m = m+1;
case 66 : m = m+1;
default: m = m+3;
}
System.out.println(m); //【代码】
}
}
{correctAnswer='5'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第19题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m = 0;
char ch ='a';
switch(ch) {
case 9 :
case 'a' : m = m+1;
case 'A' : m = m+1;
break;
case 66 : m = m+1;
default: m = m+3;
}
System.out.println(m); //【代码】
}
}
{correctAnswer='2'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第20题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m = 6789;
int [] a = new int[4];
for(int i=0;i<a.length;i++) {
a[i] = m%10;
m = m/10;
}
System.out.printf("%d%d%d%d",a[0],a[1],a[2],a[3]); //【代码】
}
}
{correctAnswer='9876'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第21题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m = 123;
int sum = 0,t = 100;
while(t > 0){
sum = sum+m%10*t;
m = m/10;
t = t/10;
}
System.out.printf("%d",sum); //【代码】
}
}
{correctAnswer='321'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第22题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
long sum = 0,a = 3,item = a,n = 3;
for(int i=1;i<=3;i++) {
sum = sum+item;
item = item*10+a;
}
System.out.println(sum); //【代码】
}
}
{correctAnswer='369'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第23题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int x = 1,y = 6;
while (y-->0) {
x--;
}
System.out.printf("%d:%d",x,y); //【代码】
}
}
{correctAnswer='-5:-1'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第24题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int []a={1,2,3},b;
int sum = 0;
b = new int[a.length];
for(int i = 0 ;i<a.length;i++){
b[i] = a[i];
}
for(int number:b){
sum += number;
}
System.out.printf("%d",sum); //【代码】
}
}
{correctAnswer='6'}

第4章

选择题

1
2
3
4
5
6
7
8
9
10

题库中第1题:
下列哪个叙述是正确的?
A. Java应用程序由若干个类所构成,这些类必须在一个源文件中。
B. Java应用程序由若干个类所构成,这些类可以在一个源文件中,也可以分布在若干个源文件中,其中必须有一个源文件含有主类。
C. Java源文件必须含有主类。
D. Java源文件如果含有主类,主类必须是public类。


{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第2题:
下列哪个叙述是正确的?
A. 成员变量的名字不可以和局部变量的相同。
B. 方法的参数的名字可以和方法中声明的局部变量的名字相同。
C. 成员变量没有默认值。
D. 局部变量没有默认值。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第3题:
对于下列Hello类,哪个叙述是正确的?
A. Hello类有2个构造方法。
B. Hello类的int Hello()方法是错误的方法。
C. Hello类没有构造方法。
D. Hello无法通过编译,因为其中的hello方法的方法头是错误的(没有类型)。
class Hello {
Hello(int m){
}
int Hello() {
return 20;
}
hello() {
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第4题:
对于下列Dog类,哪个叙述是错误的?
A. Dog(int m)与Dog(double m)互为重载的构造方法。
B. int Dog(int m)void Dog(double m)互为重载的非构造方法。
C. Dog类只有两个构造方法,而且没有无参数的构造方法。
D. Dog类有3个构造方法。
class Dog {
Dog(int m){
}
Dog(double m){
}
int Dog(int m){
return 23;
}
void Dog(double m){
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第5题:
下列哪些类(不包括内部类)声明是错误的?
A) class A
B) public class A
C) protected class A
D) class a

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第6题:
下列哪些类(不包括内部类)声明是错误的?
A. class A
B. public class A
C. protected class A
D.class a

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第7题:
下列哪些类(不包括内部类)声明是错误的?
A. class A
B. public class A
C. private class A
D. class a

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第8题:
下列哪些类(不包括内部类)声明是错误的?
A. class A
B. public class A
C. private class A
D. class a

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第9题:
将下列哪个方法添加到People类会导致编译错误?
class People {
public void f(){
}
}

A. public int f(){
return 100;
}
B. private int f(int x){
return 100+x;
}
C. protected int f(int x,int y){
return x+y;
}
D. double f(double x){
return x;
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第10题:
将下列哪个方法添加到People类不会导致编译错误?
class People {
int f(int m,int n){
return 100;
}
}

A. public int f(int x,int y){
return x+y;
}
B. float f(int m,int n){
return 100F+m*n;
}
C. byte f(short m,int n){
return (byte)(m+n);
}
D. double f(int x,int y){
return 3.14;
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10

题库中第11题:
1.下列哪个叙述是正确的?
A. 类体中必须先声明成员变量,然后再定义方法。
B. 类体中成员变量的声明和方法的定义可以交叉进行。
C. 类体中必须先定义构造方法才可以定义其他方法。
D. 类体中必须先定义实例变量,才可以再定义static变量。。


{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10

题库中第12题:
下列哪个叙述是正确的?
A. 成员变量在整个类内都有效,其有效性与它在类体中书写的先后位置无关。
B. 类体中一行只能声明一个变量。
C. 类体中,成员变量有效范围和声明的位置有关,从声明位置开始有效。
D. 方法体内不可以对成员变量进行操作,只能对方法体中声明的局部变量进行操作。


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第13题:
当用new运算符和构造方法创建对象时,下列哪个步骤的叙述是正确的?
A. 1.为成员变量分配内存,并指定默认值。
2.初始化成员变量,即用户声明成员变量时给定的默认值。
3.执行构造方法。
4.计算出一个引用值。
B. 1.计算出一个引用值。
2.为成员变量分配内存,并指定默认值。
3.初始化成员变量,即用户声明成员变量时给定的默认值。
4.执行构造方法。
C. 1.执行构造方法。
2.为成员变量分配内存,并指定默认值。
3.初始化成员变量,即用户声明成员变量时给定的默认值。
4.计算出一个引用值。
D. 1.为成员变量分配内存,并指定默认值。
2.初始化成员变量,即用户声明成员变量时给定的默认值。
3.计算出一个引用值。
4.执行构造方法。


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第14题:
对于下列Dog类,哪个叙述是正确的?
A. 有一个构造方法,是默认的不带参数的方法。
B. 有两个构造方法。
C. 没有构造方法。
D. 有3个构造方法。
class Dog {
void Dog(int m){
}
int Dog(double m){
return 100;
}
void Dog(int m,int n){
}
void Dog(float m){
}
}

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第15题:
对于下列Dog类,哪个叙述是正确的?
A. 程序运行时输出:小狗。
B. 有两个构造方法。
C. 没有构造方法。
D. 程序运行时无任何输出结果。
public class Test {
public static void main(String args[]){
Dog dog = new Dog();
}
}
class Dog {
void Dog(){
System.out.println("小狗");
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第16题:
对于下列Tom类,哪个叙述是正确的?
A. 程序运行时输出:ok。
B. 有两个构造方法。
C. 有编译错误。
D. 程序运行时输出:你好。
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("你好");
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第17题:
对于下列Tom类,哪个叙述是正确的?
A. 程序运行时输出:ok。
B. 没有构造方法。
C. 有编译错误,因为创建对象cat使用的不是构造方法,java编译器已经不提供默认的构造方法了。
D. 程序运行时无任何输出。
public class Test {
public static void main(String args[]){
Tom cat = new Tom();
}
}
class Tom {
void Tom(){
System.out.println("ok");
}
Tom(int m){
System.out.println("你好");
}
}

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第18题:
下列哪个叙述是正确的?
A. 成员变量有默认值。
B. this可以出现在static方法中。
C. 类中的实例方法可以用类名调用。
D. 局部变量也可以用访问修饰符:public,proteced,private修饰。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第19题:
下列哪个叙述是正确的?
A. 方法中声明的局部变量有默认值。
B. 方法中声明的局部变量不可以用static修饰。
C. this关键字也代表某个实例方法。
D. 构造方法也可以有返回类型。

{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第20题:
下列哪个叙述是正确的?
A.源文件可以有2条包语句(package)。
B.源文件不可以有多条import语句。
C.如果源文件有package语句,该语句也可以是源文件的第2条语句。
D.类中的类方法(static方法)只能操作类变量(static变量),不可以操作实例变量。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第21题:
下列哪个叙述是正确的?
A.如果在类中显示地定义了构造方法,Java编译器将不再提供默认的构造方法。
B.一个类不可以把某个对象作为自己的一个成员变量。
C protected class Test是一个正确的类声明,即类可以是protected类(不包括后面学习的内部类)。
D.Java应用程序由若干个类所构成,这些类必须在一个源文件中。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11

题库中第22题:
下列哪个叙述是正确的?
A. 方法中声明的局部变量可以用访问修饰符:
public,proteced,private修饰。
B. 方法中声明的局部变量可以用static修饰。
C 构造方法的访问权限必须是public。。
D. 如果源文件的包语句是package tom.jiafei;
那么可以将源文件保存在C:\1000\tom\jiafei中,然后进入到tom\jiafei的上一层目录1000中编译源文件:
C:\1000> javac tom/jiafei/源文件。
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第23题:
下列哪个叙述是正确的?
A. 编译器器不提示程序使用了空对象(让一个空对象去调用实例方法),但程序在运行时会出现NullPointerException异常。
B. 方法重载的意思是:一个类中可以有多个方法具有相同的名字,但这些方法的参数必须不同,并且返回类型必须相同。
C. static方法不可以重载。
D. 构造方法不可以重载。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第24题:
下列哪个叙述是正确的?
A. private class Test是一个正确的类声明(不包括以后学习的内部类inner class)。
B. 类中的类变量(static)在该类被加载到内存时(即使该类未创建对象)就会被分配内存空间。
C. 习惯将类名的首字母小写。
D. 类中的重载方法的访问权限必须保持一致。比如,或者都是public方法,或者都是private方法。
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第25题:
下列哪个叙述是正确的?
A. this可以出现在类方法(static方法)中。
B. Java源文件如果含有主类,主类必须是public类。。
C. 类中的实例变量在用该类创建对象的时候才会被分配内存空间。
D. 类中的实例方法可以用类名直接调用。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第26题:
下列哪个叙述是正确的?
A. 当this关键字出现在实例方法中时,就代表正在调用该方法的当前对象。
B. 一个Java源文件必须要有package语句。
C. 成员变量没有默认值。
D. 成员变量的名字不可以和局部变量的相同。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第27题:
下列哪个叙述是正确的?
A. 没有实体的对象称做空对象,程序运行时,如果一个空对象调用实例方法也不会发生异常。
B. 类的名字习惯上准守下划线规则。
C. 一个类声明的两个对象如果具有相同的引用,二者就具有完全相同的变量(实体)。
D. 如果在类中显示地定义了构造方法,Java编译器还继续提供默认的不带参数构造方法。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第28题:
下列哪个叙述是正确的?
A. 一个Java源文件必须要有package语句。
B. 一个Java源文件默认有“import java.util.*;”语句。
C. 编译器器提示程序使用了空对象(让一个空对象去调用方法)。
D. class Test是一个正确的类声明。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第29题:
下列哪个叙述是正确的?
A. 对于public类,用户定义的构造方法的访问权限也必须是public
B. 用户定义构造方法的访问权限可以是publicprotected,private或友好的。
C. Float是基本数据类型float的大写形式。
D. 习惯将方法名的首字母大写。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第30题:
下列哪个叙述是正确的?
A. 对于public类,编译器提供的默认构造方法也自动是public访问权限。
B. 一个Java源文件至多有1import语句。
C. 类体内容中定义的非构造方法是为了体现对象的属性。
D. 习惯将变量名的首字母大写。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第31题:
下列哪个叙述是正确的?
A. 对于友好类,用户定义的构造方法的访问权限也必须是public
B. 组合关系也叫is a,属于强耦合关系。
C. 当方法被调用时,参数被分配内存空间,调用者向参数传递值,即方法被调用时,参数变量必须有具体的值。
D. private class Test是一个正确的类声明(不包括以后学习的内部类inner class)。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第32题:
下列哪个叙述是正确的?
A. 一个Java源文件必须要有主类。
B. 类体中声明成员变量是为了体现对象的行为(功能)。
C. 可以把int型数据赋值给类声明的对象变量。
D. 类所声明的变量被称为对象,对象(变量)负责存放引用,以确保对象可以操作分配给该对象的变量以及调用类中的方法。分配给对象的变量被习惯地称做对象的实体。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10

题库中第33题:
下列哪个叙述是正确的?
A. 当类中没有定义任何构造方法时,Java编译器将为这个类提供默认构造方法
B. Java编译器提供的默认构造方法,也可以为成员变量重新赋值。
C. Java编译器会为所有的类提供默认构造方法。
D. 如果在一个类中定义的构造方法都是有参数的,Java编译器将为这个类提供默认构造方法。


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第34题:
下列哪个叙述是错误的?
A. 实例变量是类的成员变量。
B. 在方法中定义的局部变量在该方法被执行时分配内存 。
C. 局部变量在使用前必须要有值。
D. 实例变量用关键字static修饰。


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第35题:
对于下列Tom类,哪个叙述是正确的?
A. 程序运行时输出:ok100。
B. 有3个构造方法。
C. 有编译错误。
D. 程序运行时输出:你好100
public class Test {
public static void main(String args[]){
Tom cat1 = new Tom();
Tom cat2 = new Tom(100);
}
}
class Tom {
void Tom(){
System.out.print("ok");
}
Tom(){
System.out.print("你好");
}
Tom(int n){
System.out.print(n);
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第36题:
对于下列Tom类,哪个叙述是正确的?
A. 程序运行时输出:100
B. 有2个构造方法。
C. 有编译错误。
D. 程序运行时输出:hello100。
public class Test {
public static void main(String args[]){
Tom cat1 = new Tom();
Tom cat2 = new Tom(100);
}
}
class Tom {
void Tom(){
System.out.print("hello");
}
Tom(int n){
System.out.print(n);
}
}

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

题库中第37题:
将下列哪个方法添加到People类不会导致编译错误?
class People {
public void f(){
}
private int f(int x){
return 100+x;
}
protected int f(int x,int y){
return x+y;
}
}

A. public int f(){
return 100;
}
B. private int f(int m){
return 100+m;
}
C. protected long f(int m,int n){
return m+n;
}
D. double f(double x){
return x;
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第38题:
对于下列代码E.java,哪个叙述是正确的?
A.代码没有编译错误。
B.代码可以通过编译,但运行时触发NullPointException。
C.代码有编译错误提示:无法从静态上下文中引用非静态变量 x。
D.start方法中操作变量 y 导致编译错误。
public class E {
int x;
static int y;
void start(){
x = 100;
y = 200;
}
static void stop() {
x = 1000;
y = 2000;
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第39题:
下列哪个代码体现了组合关系,即has a?
A.
class AAA {
Integer number;
}
B.
class BBB {
int number;
}
C.
class CCC {
void f(Integer n){}
}
D.
class DDD {
float c;
}

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第40题:
下列哪些叙述是正确的?(多选)
A. 类是Java语言中最重要的“数据类型”,类声明的变量被称做对象变量,简称对象。
B. 类体中声明成员变量是为了体现对象的属性。
C. 类所声明的变量被称为对象,对象(变量)负责存放引用,
以确保对象可以操作分配给该对象的变量以及调用类中的方法。分配给对象的变量被习惯地称做对象的实体。
D. this可以出现在类方法(static方法)中。

{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9
10

题库中第41题:
下列哪个叙述是错误的?
A. 类是Java语言中最重要的“数据类型”,类声明的变量被称做对象变量,简称对象。
B. 类体中声明成员变量是为了体现对象的属性。
C. 类所声明的变量被称为对象,对象(变量)负责存放引用,
以确保对象可以操作分配给该对象的变量以及调用类中的方法。分配给对象的变量被习惯地称做对象的实体。
D. this可以出现在类方法(static方法)中。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第42题:
下列哪个叙述是错误的?
A. 如果源文件有package语句,该语句必须是源文件的第一条语句。
B. 一个Java源文件必须要有package语句。
C. 一个Java源文件默认有“import java.lang.*;”语句。
D. 一个Java源文件可以有多条import语句。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第43题:
下列哪个叙述是正确的?
A. 成员变量的名字不可以和局部变量的相同。
B. 方法的参数的名字可以和方法中声明的局部变量的名字相同。
C. 成员变量没有默认值。
D. 局部变量没有默认值。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第44题:
下列哪些叙述是错误的?(多选)
A. 成员变量的名字不可以和局部变量的相同。
B. 方法的参数的名字可以和方法中声明的局部变量的名字相同。
C. 成员变量没有默认值。
D. 局部变量没有默认值。

{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9

题库中第45题:
下列哪个叙述是错误的?
A. 一个类声明的两个对象如果具有相同的引用,二者就具有完全相同的变量(实体)。
B. 一个类中可以有多个方法具有相同的名字,但这些方法的参数必须不同。
C. static方法不可以重载。
D. 如果在类中显示地定义了构造方法,Java编译器将不再提供默认的构造方法。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第46题:
下列哪个叙述是错误的?
A. 类中的重载方法的访问权限必须保持一致。比如,或者都是public方法,或者都是private方法。
B. 方法中声明的局部变量不可以用访问修饰符:public,proteced,private修饰。
C. 方法中声明的局部变量不可以用static修饰。
D. 方法中声明的局部变量的名字不可以和方法的参数的名字相同。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第47题:
下列哪个叙述是错误的?
A. 类中的static方法可以用类名调用。
B. 实例方法可以操作static变量。
C. 类方法(static方法)可以操作实例变量。
D. 类方法(static方法)可以操作static变量。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第48题:
下列哪些叙述是正确的?(多选)
A. 类中的static方法可以用类名调用。
B. 实例方法可以操作static变量。
C. 类方法(static方法)可以操作实例变量。
D. 类方法(static方法)可以操作static变量。

{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9

题库中第49题:
下列哪些叙述是正确的?(多选)
A. Double是java.lang包中一个类的名字,而double是java的关键字,用来声明double基本类型变量。
B. 构造方法的访问权限必须是public
C. 一个类可以把某个对象作为自己的一个成员变量。
D. 成员变量的名字可以和局部变量的相同。

{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9

题库中第50题:
下列哪些叙述是正确的?(多选)
A. 习惯将方法名及变量名的首字母小写。
B. 构造方法的访问权限可以是publicprotected,private或友好的。
C. 局部变量有默认值。
D. 如果在类中显示地定义了构造方法,Java编译器将不再提供默认的构造方法。

{correctAnswer='ABD'}

判断题

1
2
3
4

题库中第1题:
类是Java语言中最重要的“数据类型”,类声明的变量被称做对象变量,简称对象。
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
类体中声明成员变量是为了体现对象的属性。
{correctAnswer='正确'}
1
2
3
4
5

题库中第3题:
类所声明的变量被称为对象,对象(变量)负责存放引用,以确保对象可以操作分配给该对象的变量以及调用类中的方法。
分配给对象的变量被习惯地称做对象的实体。
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
类体内容中定义的非构造方法是为了体现对象的行为。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
构造方法没有类型。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
类中的实例变量在用该类创建对象的时候才会被分配内存空间。
{correctAnswer='正确'}
1
2
3
4

题库中第7题:
构造方法也可以重载。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
类中的实例方法可以用类名直接调用。
{correctAnswer='错误'}
1
2
3
4

题库中第9题:
类中的类方法可以用类名直接调用。
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
this关键字代表某个对象。
{correctAnswer='正确'}
1
2
3
4

题库中第11题:
类中的实例方法可以操作类变量(static变量),也可以操作实例变量。
{correctAnswer='正确'}
1
2
3
4

题库中第12题:
类中的类方法(static方法)只能操作类变量(static变量),不可以操作实例变量。
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
this可以出现在类方法(static方法)中。
{correctAnswer='错误'}
1
2
3
4

题库中第14题:
this可以出现在实例方法和构造方法中。
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
源文件至多有一条包语句(package)。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
源文件可以有多条import语句。
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
如果源文件有package语句,该语句必须是源文件的第一条语句。
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
Java应用程序由若干个类所构成,这些类必须在一个源文件中。
{correctAnswer='错误'}
1
2
3
4

题库中第19题:
Java应用程序由若干个类所构成,这些类可以在一个源文件中,也可以分布在若干个源文件中。
{correctAnswer='正确'}
1
2
3
4

题库中第20题:
一个Java源文件必须要有主类。
{correctAnswer='错误'}
1
2
3
4

题库中第21题:
Java源文件如果含有主类,主类必须是public类。
{correctAnswer='错误'}
1
2
3
4

题库中第22题:
一个Java源文件必须要有package语句。
{correctAnswer='错误'}
1
2
3
4

题库中第23题:
一个Java源文件默认有“import java.lang.*;”语句。
{correctAnswer='正确'}
1
2
3
4

题库中第24题:
一个Java源文件可以有多条import语句。
{correctAnswer='正确'}
1
2
3
4

题库中第25题:
成员变量的名字不可以和局部变量的相同。
{correctAnswer='错误'}
1
2
3
4

题库中第26题:
方法的参数的名字可以和方法中声明的局部变量的名字相同。
{correctAnswer='错误'}
1
2
3
4

题库中第27题:
成员变量没有默认值。
{correctAnswer='错误'}
1
2
3
4

题库中第28题:
局部变量没有默认值。
{correctAnswer='正确'}
1
2
3
4

题库中第29题:
类的名字在习惯上准守驼峰规则。
{correctAnswer='正确'}
1
2
3
4

题库中第30题:
习惯将方法名及变量名的首字母小写。
{correctAnswer='正确'}
1
2
3
4

题库中第31题:
如果在类中显示地定义了构造方法,Java编译器将不再提供默认的构造方法。
{correctAnswer='正确'}
1
2
3
4

题库中第32题:
一个类可以把某个对象作为自己的一个成员变量。
{correctAnswer='正确'}
1
2
3
4

题库中第33题:
protected class Test是一个错误的类声明,即类不可以是protected类(不包括以后学习的内部类inner class)。
{correctAnswer='正确'}
1
2
3
4

题库中第34题:
private class Test是一个错误的类声明,即类不可以是private类(不包括以后学习的内部类inner class)。
{correctAnswer='正确'}
1
2
3
4

题库中第35题:
public class Test是一个正确的类声明,即类可以是public类。
{correctAnswer='正确'}
1
2
3
4

题库中第36题:
class Test是一个正确的类声明,即类可以是友好类。
{correctAnswer='正确'}
1
2
3
4

题库中第37题:
Float是java.lang包中一个类的名字,而float是java的关键字,用来声明float基本类型变量。
{correctAnswer='正确'}
1
2
3
4

题库中第38题:
一个类声明的两个对象如果具有相同的引用,二者就具有完全相同的变量(实体)。
{correctAnswer='正确'}
1
2
3
4

题库中第39题:
没有实体的对象称做空对象,应当仔细检查,避免使用空对象,即让一个空对象去调用方法产生行为。
{correctAnswer='正确'}
1
2
3
4

题库中第40题:
组合关系也叫has a,属于弱耦合关系。
{correctAnswer='正确'}
1
2
3
4

题库中第41题:
编译器器不提示程序使用了空对象(让一个空对象去调用实例方法),但程序在运行时会出现NullPointerException异常。
{correctAnswer='正确'}
1
2
3
4

题库中第42题:
方法重载的意思是:一个类中可以有多个方法具有相同的名字,但这些方法的参数必须不同。
{correctAnswer='正确'}
1
2
3
4

题库中第43题:
static方法不可以重载。
{correctAnswer='错误'}
1
2
3
4

题库中第44题:
构造方法不可以重载。
{correctAnswer='错误'}
1
2
3
4

题库中第45题:
在Java中,方法的所有参数都是“传值”的,也就是说,方法中参数变量的值是调用者指定的实参值的拷贝。
{correctAnswer='正确'}
1
2
3
4

题库中第46题:
当方法被调用时,参数被分配内存空间,调用者向参数传递值,即方法被调用时,参数变量必须有具体的值。
{correctAnswer='正确'}
1
2
3
4

题库中第47题:
类中的类变量(static)在该类被加载到内存时(即使该类未创建对象)就会被分配内存空间。
{correctAnswer='正确'}
1
2
3
4

题库中第48题:
类中的重载方法的访问权限必须保持一致。比如,或者都是public方法,或者都是private方法。
{correctAnswer='错误'}
1
2
3
4

题库中第49题:
构造方法的访问权限必须是public
{correctAnswer='错误'}
1
2
3
4

题库中第50题:
构造方法的访问权限可以是publicprotected,private或友好的。
{correctAnswer='正确'}
1
2
3
4
5
6

题库中第51题:
如果源文件的包语句是package tom.jiafei;
那么可以将源文件保存在C:\1000\tom\jiafei中,然后进入到tom\jiafei的上一层目录1000中编译源文件:
C:\1000> javac tom\jiafei\源文件
{correctAnswer='正确'}
1
2
3
4
5
6
7

题库中第52题:
如果主类的包名是tom.jiafei,那么主类的字节码一定存放在…\tom\jiafei目录中,那么必须到tom\jiafei的上一层(即tom的父目录)目录中去运行主类。假设tom\jiafei的上一层目录是1000,那么,必须用如下格式来运行:

C:\1000> java tom.jiafei.主类名

{correctAnswer='正确'}
1
2
3
4
5

题库中第53题:
方法中声明的局部变量不可以用访问修饰符:public,proteced,private修饰。

{correctAnswer='正确'}
1
2
3
4
5

题库中第54题:
方法中声明的局部变量不可以用static修饰。

{correctAnswer='正确'}
1
2
3
4
5

题库中第55题:
方法中声明的局部变量的名字不可以和方法的参数的名字相同。

{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
public class People {
int m = 10,n; //A
n = 200; //B
void f(){
if(m == n)
n =+ m; //C
else
n = n - m; //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
class Hello {
Hello(int m) //A
{
}
int Hello() //B
{
return 20;
}
hello() //C
{
}
void go() //D
{
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
class E {
int x;
long y = x //A
y = x; //B
public void f(int n) {
int m = 0; //C
int t = n+m; //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
class E {
int x;
long y = x //A
y = x; //B
public void f(int n) {
int m = 0; //C
int t = n+m; //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
class E {
int x;
public void f(int n) {
int m; //A
int t = x+n; //B
int y = x+m; //C
m = 10;
y = x+m; //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第6题:
下列ABCD注释标注的哪行代码有错误?
class E {
int x; //A
long y = x //B
public void f(int n) {
int m ; //C
int t = n+m; //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第7题:
下列ABCD注释标注的哪行代码有错误?
class E {
int x;
long y = x //A
public void f(int n) {
int m ; //B
int p = 0;
int t = n+m; //C
y = n+p; //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第8题:
下列ABCD注释标注的哪行代码有错误?
class E {
public void move() {
int n = m; //A
}
int m;
void start(){
c = 'a'; //B
n = 200; //C
}
char c;
void stop() {
c = 'A';
x = 2025; //D
}
int x;
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第9题:
下列ABCD注释标注的哪行代码有错误?
class E {
int x;
static int y;
void start(){
x = 100; //A
y = 200; //B
}
static void stop() {
x = 1000; //C
y = 2000; //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第10题:
下列ABCD注释标注的哪行代码有错误?
class Tom {
int x;
static int y;
void showXY(){
System.out.printf("%d,%d\n",x,y);
}
static void showY() {
System.out.printf("%d\n",y);
}
}
public class E {
public static void main(String aqgs[]){
Tom.y = 100; //A
Tom cat = new Tom();
cat.x = 100;
cat.y = 200; //B
Tom.x = 300; //C
cat.showXY();
Tom.showY(); //D

}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第11题:
下列ABCD注释标注的哪行代码有错误?
class Tom {
int x;
static int y;
void showXY(){
System.out.printf("%d,%d\n",x,y);
}
static void showY() {
System.out.printf("%d\n",y);
}
}
public class E {
public static void main(String aqgs[]){
Tom.y = 300; //A
Tom cat = new Tom();
cat.x = 100; //B
Tom.showXY(); //C
cat.showY(); //D

}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第12题:
下列ABCD注释标注的哪行代码有错误?
class Tom {
private int x = 120;
protected int y = 20;
int z = 11;
private void f() {
x = 200;
System.out.println(x);
}
void g() {
x = 200;
System.out.println(x);
}
}
public class E {
public static void main(String args[]) {
Tom tom = new Tom();
tom.x = 22; //A
tom.y = 33; //B
tom.z = 55; //C
tom.g(); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第13题:
下列ABCD注释标注的哪行代码有错误?
class Tom {
private int x = 120;
protected int y = 20;
int z = 11;
private void showX() {
System.out.println(x);
}
public void setX(int x) {
this.x = x;
System.out.println(x);
}
}
public class E {
public static void main(String args[]) {
Tom tom = new Tom();
tom.setX(22); //A
tom.y = 33; //B
tom.z = 55; //C
tom.showX(); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第14题:
下列ABCD注释标注的哪行代码有错误?
class A {
int f(int x,int y){
int x; //A
int m = y; //B
return m;
}
int A(int m) //C
{
return m;
}
}
public class E {
public static void main(String args[]) {
A a = new A(); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第15题:
下列ABCD注释标注的哪行代码有错误?
class Tom {
void Tom() //A
{
System.out.print("ok");
}
Tom(byte m) //B
{
System.out.print("你好");
}
Tom(int m) //C
{
System.out.print(":"+m);
}
}
public class E {
public static void main(String args[]) {
Tom a = new Tom(); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第16题:
下列ABCD注释标注的哪行代码有错误?
class Tom {
void Tom(){
System.out.print("ok");
}
Tom(byte m) {
System.out.print("你好");
}
Tom(int m) {
System.out.print(m);
}
}
public class E {
public static void main(String args[]) {
Tom a = new Tom(); //A
Tom b = new Tom(127); //B
Tom c = new Tom((byte)127); //C
Tom d = new Tom('好'); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第17题:
下列ABCD注释标注的哪行代码有错误?
package china.beijing;
package china.beijing; //A
class People {
static void speak(){
System.out.print("take care of");
}
void People(int m) // B
{
}
}
public class E {
public static void main(String args[]) {
People zh = new People(); //C
zh.speak(); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第18题:
下列ABCD注释标注的哪行代码有错误?
public class Animal //A
{}
class Dog //B
{}
protected class Cat //C
{}
class _class //D
{}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第19题:
下列ABCD注释标注的哪行代码有错误?
public class Animal //A
{}
private class Dog //B
{}
class Cat //C
{}
class _class //D
{}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第20题:
下列ABCD注释标注的哪行代码有错误?
class Bird {
Cat cat; //A
int height;
}
class Cat {
int leg;
}
public class E {
public static void main(String args[]) {
Bird bird = new bird(); //B
Cat cat = new Cat(); //C
cat.leg = 4; //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第21题:
下列ABCD注释标注的哪行代码有错误?
class Bird {
Cat cat; //A
int height;
}
class Cat {
int leg;
}
public class E {
public static void main(String args[]) {
Bird bird = new Bird(); //B
Cat cat = new cat(); //C
cat.leg = 4; //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第22题:
下列ABCD注释标注的哪行代码有错误?
class Cat {
int leg;
static int water;
void setLeg(int leg) {
this.leg = leg; //A
this.water = 100; //B
}
static void setWater(int water) {
this.water = water; //C
Cat.water = water; //D
}
}

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第23题:
下列ABCD注释标注的哪行代码有错误?
class Cat {
int leg;
static int water;
void setLeg(int leg) {
this.leg = leg; //A
this.water = 100; //B
}
static void setWater(int water) {
Cat.water = water; //C
leg = 4; //D
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第24题:
下列ABCD注释标注的哪行代码无编译错误,但运行时刻触发NullPointerException异常?
class Cat {
int leg;
static int water;
void setLeg(int leg) {
this.leg = leg; //A
this.water = 100; //B
}
static void setWater(int water) {
Cat.water = water; //C
}
}
public class E {
public static void main(String args[]) {
Cat cat = null;
cat.setLeg(4); //D
}
}

{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
class Tom {
int weight = 10;
void Tom(){
weight = 18;
}
}
public class E {
public static void main(String args[]) {
Tom cat = new Tom();
System.out.println(cat.weight); //【代码】
}
}
{correctAnswer='10'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
class Tom {
int weight = 10;
public Tom(){
weight = 18;
}
}
public class E {
public static void main(String args[]) {
Tom cat = new Tom();
System.out.println(cat.weight); //【代码】
}
}
{correctAnswer='18'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
class Tom {
int weight = 10;
}
public class E {
public static void main(String args[]) {
Tom cat = new Tom();
System.out.println(cat.weight); //【代码】
}
}
{correctAnswer='10'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
class Car {
int speed;
void upSpeed(int m){
if(m>0)
speed += m;
}
}
public class E {
public static void main(String args[]) {
Car carOne = new Car();
Car carTwo = new Car();
carOne.upSpeed(50);
carTwo.upSpeed(100);
System.out.printf("%d:%d",carOne.speed,carTwo.speed); //【代码】
}
}
{correctAnswer='50:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
class People {
int money;
static int water;
void addMoney(int m){
money += m;
}
void addWater(int w){
water += w;
}
}
public class E {
public static void main(String args[]) {
People sun = new People();
People zh = new People();
sun.addMoney(5);
zh.addMoney(10);
sun.addWater(5);
zh.addWater(10);
System.out.printf("%d:%d",sun.money,sun.water); //【代码】
}
}
{correctAnswer='5:15'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
class People {
int money;
static int water;
void addMoney(int m){
money += m;
}
void addWater(int w){
water += w;
}
}
public class E {
public static void main(String args[]) {
People sun = new People();
People zh = new People();
sun.addMoney(5);
zh.addMoney(10);
sun.addWater(5);
zh.addWater(10);
System.out.printf("%d:%d",zh.money,zh.water); //【代码】
}
}
{correctAnswer='10:15'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
class AAA {
static int m ;
static {
m = 888;
}
}
public class E {
public static void main(String args[]) {
AAA a= null;
System.out.printf("%d:%d",AAA.m,a.m);
}
}
{correctAnswer='888:888'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第8题:
给出下列【代码】注释标注的代码的输出结果。
class Tom {
int sum;
int getSum(int m,int ... item ){
sum = m;
for(int n:item){
sum += n;
}
return sum;
}
}
public class E {
public static void main(String args[]) {
Tom tom = new Tom();
int resultOne = tom.getSum(0,1,2,3,4,5);
int resultTwo = tom.getSum(10,7,13,15,5,9);
System.out.printf("%d:%d",resultOne,resultTwo); //【代码】
}
}
{correctAnswer='15:59'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第9题:
给出下列【代码】注释标注的代码的输出结果。
class A {
int f(int x,double y) {
return x+(int)y;
}
int f(int x,int y) {
return x*y;
}
}
public class E {
public static void main(String args[]) {
A a=new A();
System.out.printf("%d:%d",a.f(10,10),a.f(10,10.0)); //【代码】
}
}
{correctAnswer='100:20'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第10题:
给出下列【代码】注释标注的代码的输出结果。
class B {
int n;
static int sum=0;
void setN(int n) {
this.n=n;
}
int getSum() {
for(int i=1;i<=n;i++)
sum=sum+i;
return sum;
}
}
public class E {
public static void main(String args[]) {
B b1=new B(),b2=new B();
b1.setN(3);
b2.setN(5);
int s1=b1.getSum();
int s2=b2.getSum();
System.out.printf("%d:%d",s1,s2);
}
}
{correctAnswer='6:21'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第11题:
给出下列【代码】注释标注的代码的输出结果。
class B {
int x = 100,y = 200;
public void setX(int x) {
x = x;
}
public void setY(int y) {
this.y = y;
}
public int getXYSum() {
return x+y;
}
}
public class E {
public static void main(String args[]) {
B b = new B();
b.setX(-100);
b.setY(88);
System.out.printf("%d:%d:%d",b.x,b.y,b.getXYSum());
}
}
{correctAnswer='100:88:188'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第12题:
给出下列【代码】注释标注的代码的输出结果。
class Fish {
int weight = 1;
}
class Lake {
Fish fish;
void setFish(Fish s){
fish = s;
}
void foodFish(int m) {
fish.weight=fish.weight+m;
}
}
public class E {
public static void main(String args[]) {
Fish redFish = new Fish();
Lake lake = new Lake();
lake.setFish(redFish);
lake.foodFish(120);
System.out.printf("%d:%d",redFish.weight,lake.fish.weight); //【代码】
}
}
{correctAnswer='121:121'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第13题:
给出下列【代码】注释标注的代码的输出结果。
class Lake {
Fish fish;
void setFish(Fish s){
fish = s;
}
void foodFish(int m) {
fish.weight=fish.weight+m;
}
Fish getFish(){
fish.weight -= 10;
return fish;
}
}
public class E {
public static void main(String args[]) {
Fish redFish = new Fish();
Lake lake = new Lake();
lake.setFish(redFish);
lake.foodFish(120);
int w = lake.fish.weight;
Fish fishOK = lake.getFish();
System.out.printf("%d:%d:%d",w,lake.fish.weight,fishOK.weight); //【代码】
}
}
{correctAnswer='121:111:111'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

题库中第14题:
给出下列【代码】注释标注的代码的输出结果。
class Circle {
int radius = 1 ;
void setRadius(int radius){
if(radius>0)
this.radius = radius;
}
}
class Geometry {
Circle c;
void setCircle(Circle c) {
c.radius += 10;
this.c = c;
}

}
public class E {
public static void main(String args[]) {
Circle circle = new Circle();
circle.setRadius(10);
Geometry geometry = new Geometry();
int r = circle.radius;
geometry.setCircle(circle);
System.out.printf("%d:%d:%d",r,geometry.c.radius,circle.radius); //【代码】
}
}



{correctAnswer='10:20:20'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第15题:
给出下列【代码】注释标注的代码的输出结果。
class Tom {
static int sum;
int getSum(int ... item ){
for(int n:item){
sum += n;
}
return sum;
}
}
public class E {
public static void main(String args[]) {
Tom cat1 = new Tom();
Tom cat2 = new Tom();
int resultOne = cat1.getSum(1,2,3,4);
int resultTwo = cat2.getSum(10,30);
System.out.printf("%d:%d",resultOne,resultTwo); //【代码】
}
}
{correctAnswer='10:50'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第16题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m =100,n =10;
if(m > n) {
n = 100;
m = 10;
}
else
n = -100;
m = -99;
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='-99:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第17题:
给出下列【代码】注释标注的代码的输出结果。
public class Test {
public static void main (String args[ ]) {
int m =100,n =10;
if(m > n) {
n = 100;
m = 10;
}
else {
n = -100;
m = -99;
}
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='10:100'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第18题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
int [] a = {12,3,9,23,45,9,-100};
java.util.Arrays.sort(a);
int index=java.util.Arrays.binarySearch(a,9);
System.out.printf("%d:%d",index,a[index]); //【代码】
}
}
{correctAnswer='3:9'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第19题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
int [] a = {12,3,9,23,45,9,-100};
java.util.Arrays.sort(a);
int index=java.util.Arrays.binarySearch(a,-100);
System.out.printf("%d:%d",index,a[index]); //【代码】
}
}
{correctAnswer='0:-100'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第20题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
int [] a = {12,3,9,23,45,9,-100};
java.util.Arrays.sort(a);
int index=java.util.Arrays.binarySearch(a,45);
System.out.printf("%d:%d",index,a[index]); //【代码】
}
}
{correctAnswer='6:45'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第21题:
给出下列【代码】注释标注的代码的输出结果。
import java.lang.Math;
public class E {
public static void main(String args[]) {
int m = (int)Math.sqrt(9);
int n = Math.abs(-20);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='3:20'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第22题:
给出下列【代码】注释标注的代码的输出结果。
class Computer {
static long getSum(int a,int n){
long sum = 0,item = a;
for(int i=1;i<=n;i++) {
sum = sum+item;
item = item*10+a;
}
return sum;
}
}
public class E {
public static void main(String args[]) {
long m = Computer.getSum(1,5);
long n = Computer.getSum(2,3);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='12345:246'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

题库中第23题:
给出下列【代码】注释标注的代码的输出结果。
class Circle {
int radius = 1 ;
void setRadius(int radius){
if(radius>0)
this.radius = radius;
}
}
class Geometry {
Circle c;
void setCircle(Circle c) {
c.radius += 10;
this.c = c;
}
}
public class E {
public static void main(String args[]) {
Circle circle = new Circle();
circle.setRadius(10);
Geometry geometry = new Geometry();
geometry.setCircle(circle);
Circle circleTwo = new Circle();
geometry.setCircle(circleTwo);
System.out.printf("%d:%d",circle.radius,geometry.c.radius); //【代码】
}
}
{correctAnswer='20:11'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第24题:
给出下列【代码】注释标注的代码的输出结果。
class Family{
int height;
static char surname;
}
public class E {
public static void main(String args[]) {
Family boy = new Family();
Family girl = new Family();
boy.surname ='张';
girl.surname ='孙';
boy.height = 176;
girl.height =166;
System.out.printf("%c:%c:%d:%d",
boy.surname,girl.surname,
boy.height,girl.height); //【代码】
}
}
{correctAnswer='孙:孙:176:166'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

题库中第25题:
给出下列【代码】注释标注的代码的输出结果。
import java.lang.Character;
class Letter{
char [] ch;
Letter(char [] ch){
this.ch = ch;
}
int getDigitAmount(){
int amount = 0;
for(char c:ch) {
if(Character.isDigit(c))
amount++;
}
return amount;
}
int getLetterAmount(){
int amount = 0;
for(char c:ch) {
if(Character.isLetter(c))
amount++;
}
return amount;
}
int getOtherAmount(){
int amount = 0;
for(char c:ch) {
if(!Character.isLetter(c)&&!Character.isDigit(c))
amount++;
}
return amount;
}
}
public class E {
public static void main(String args[]) {
char [] a = {'a','b','?','*','c','9','0','*'};
Letter tom = new Letter(a);
System.out.printf("%d:%d:%d",tom.getLetterAmount(),
tom.getDigitAmount(),
tom. getOtherAmount()); //【代码】
}
}
{correctAnswer='3:2:3'}
1
2
3
4
5
6
7
8
9
10
11

题库中第26题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
char [] c = {'y','b','o'};
java.util.Arrays.sort(c);
System.out.printf("%c%c%c",c[0],c[1],c[2]); //【代码】
}
}
{correctAnswer='boy'}
1
2
3
4
5
6
7
8
9
10
11

题库中第27题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
int [] c = {10,9,2,8};
java.util.Arrays.sort(c);
System.out.printf("%d%d%d%d",c[0],c[1],c[2],c[3]);//【代码】
}
}
{correctAnswer='28910'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第28题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
int [] c = {10,9,-2,8};
java.util.Arrays.sort(c);
int index1=java.util.Arrays.binarySearch(c,19);
int index2=java.util.Arrays.binarySearch(c,-2);
System.out.printf("%b:%b",index1<0,index2>=0); //【代码】
}
}
{correctAnswer='true:true'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第29题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.Arrays;
public class E {
public static void main(String args[]) {
int [] source = {100,200,500,4,5,6};
int [] copy=Arrays.copyOfRange(source,0,2); //复制数组source,下标[0,2)范围
System.out.printf("%d:%d:%d",copy[0],copy[1],copy.length); //【代码】
}
}
{correctAnswer='100:200:2'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第30题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.Arrays;
public class E {
public static void main(String args[]) {
int [] source = {100,200,500,4,5,6};
int [] copy=Arrays.copyOfRange(source,1,3); //复制数组source,下标[1,3)范围
System.out.printf("%d:%d:%d",copy[0],copy[1],copy.length); //【代码】
}
}
{correctAnswer='200:500:2'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第31题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.Arrays;
public class E {
public static void main(String args[]) {
int [] source = {100,200,500,4,5,6};
int [] copy=Arrays.copyOf(source,3); //复制数组source,下标[0,3)范围
System.out.printf("%d:%d:%d",copy[0],copy[1],copy[2]); //【代码】
}
}
{correctAnswer='100:200:500'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第32题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.Arrays;
public class E {
public static void main(String args[]) {
char [] source = {'N','B','A','O','K'};
char [] copy=Arrays.copyOf(source,3); //复制数组source,下标[0,3)范围
System.out.printf("%c%c%c",copy[0],copy[1],copy[2]); //【代码】
}
}
{correctAnswer='NBA'}

第5章

选择题

1
2
3
4
5
6
7
8
9
10

题库中第1题:
下列哪个叙述是正确的?
A. 子类继承父类的构造方法。
B. abstract类的子类必须是非abstract类。
C. 子类继承的方法只能操作子类继承和隐藏的成员变量。
D. 子类重写或新增的方法也能直接操作被子类隐藏的成员变量


{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第2题:
下列哪个叙述是正确的?
A.final 类可以有子类。
B.abstract类中只可以有abstract方法。
C.abstract类中可以有非abstract方法,但该方法不可以用final修饰。
D.不可以同时用finalabstract修饰同一个方法。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第3题:
对于下列Hello类,哪个叙述是正确的?
A. 不允许使用static修饰abstract方法。。
B. 可以同时用finalabstract修饰同一个方法。
C. abstract类中不可以有非abstract方法。
D.final 类不可以有父类。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第4题:
对于下列Dog类,哪个叙述是错误的?
A. 用户在定义子类时,可以给子类指定多个父类。
B. 除了java.lang.Object类,任何一个类有且仅有一个父类。
C. 一个非final类可以有多个子类。
D. 类声明class Aclass A extends Object是等价的。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第5题:
下列哪个叙述是正确的?
A. java.lang包中的Object类是所有其他类的父亲。
B.如果子类和父类不在同一个包中,子类也继承父类的友好成员。
C.所谓子类继承父类的成员变量作为自己的一个成员变量,就好象它们是在子类中直接声明一样,
可以被子类中自己定义的任何实例方法操作。
D.final类至多可以有一个子类。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第6题:
下列哪个叙述是正确的?
A.如果在子类中想使用被子类隐藏的成员变量或方法就需要使用关键字super
B.子类不可以声明和父类同名的成员变量。
C.子类继承父类的构造方法。
D.子类不可以定义和父类同名的方法。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第7题:
下列哪个叙述是正确的?
A. 子类不继承父类的构造方法。
B. 可以用final修饰构造方法。
C. 可以用static修饰构造方法。
D. 用户在定义子类时,可以给子类指定多个父类。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第8题:
下列哪个叙述是正确的?
A. super关键字形成的语句可以是子类构造方法的第2条语句。
B. 如果在子类的构造方法中,没有显示地写出super关键字来调用父类的某个构造方法,那么编译器默认地有:super();调用父类的无参数的构造方法(如果父类没有这样的构造方法,代码将出现编译错误).
C. 在子类的构造方法中,不可以显示地写出super关键字来调用父类的构造方法。
D. 子类构造方法字可以有多条super调用父类的某个构造方法的语句。

{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第9题:
下列哪个叙述是正确的?
A. 在子类的构造方法中显示地写出super时,super关键字形成的语句必须是子类构造方法的第1条语句。
B. 子类和父类必须在一个包中。
C. 可以同时用finalabstract修饰同一个方法。
D. abstract类中,必须要有abstract方法。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第10题:
下列哪个叙述是正确的?
A. abstract类中用户不能写构造方法。
B. 可以用new运算符和abstract类的构造方法创建对象。
C. abstract类中,必须要有abstract方法。。
D. 如果一个类中有abstract方法,这个类必须是abstract类。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10

题库中第11题:
下列哪个叙述是正确的?
A.如果子类可以继承父类的某个方法,那么子类就有权利重写这个方法。
B.子类在方法重写时,可以把父类的类(static)方法重写为实例方法。
C.子类在方法重写时,可以把父类的实例方法重写为类(static)方法。
D.子类在方法重写时,可以重写父类的final方法。


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第12题:
对于下列代码,下列哪个叙述是正确的?
class People {
People(int m) {
}
}
class Student extends People {

}
A. 可以用People类以及无参数构造方法创建对象:new People()。
B. 可以用Student类以及无参数构造方法创建对象:new Student()。
C. 代码无法通过编译。
(原因是,父类People已经没有了不带参数的构造方法,而子类Student构造方法默认调用People类的不带参数的构造方法)。
.
D. People类不能创建对象。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第13题:
对于下列代码,下列哪个叙述是正确的?
class Animal{
int m;
Animal(){
m = 100;
}
Animal(int m) {
this.m = m;
}
}
class Dog extends Animal {
Dog() {
m += 10;
}
}
public class E {
public static void main(String args[]){
Dog dog = new Dog();
System.out.println(dog.m);
}
}
A. 有编译错误。
B. 运行输出结果是10
C. 运行输出结果是100
D. 运行输出结果是110
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

题库中第14题:
对于下列代码,下列哪个叙述是正确的?
class Animal{
int m;
Animal(){
m = 100;
}
Animal(int m) {
this.m = m;
}
}
class Dog extends Animal {
Dog() {
super(8);
m += 10;
}
}
public class E {
public static void main(String args[]){
Dog dog = new Dog();
System.out.println(dog.m);
}
}
A. 有编译错误。
B. 运行输出结果是10
C. 运行输出结果是18
D. 运行输出结果是110
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第15题:
下列哪个叙述是正确的?
A.子类重写父类的方法时,不允许降低方法的访问权限,但可以提高访问权限。
B.子类在方法重写时,可以把父类的public方法重写为private方法。
C.子类在方法重写时,可以把父类的public方法重写为protected方法。
D.如果子类不是abstract类,也允许子类将父类的非abstract方法重写为abstract方法。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第16题:
下列哪个叙述是正确的?
A.能用static修饰构造方法。
B.子类在方法重写时,可以把父类的友好方法重写为private方法。
C.子类在方法重写时,可以把父类的protected方法重写为友好方法。
D.如果子类是abstract类,允许子类将父类的非abstract方法重写为abstract方法。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第17题:
下列哪个叙述是正确的?
A.如果一个非抽象类是某个抽象类的子类,那么它必须重写父类的抽象方法,即给出方法体(将abstract方法重写为非abstract方法)。
B.如果一个抽象类是某个抽象类的子类,那么它也必须将父类abstract方法重写为非abstract方法。
C.子类对象的上转型对象能操作子类新增的成员变量.(失掉了这部分属性),不能调用子类新增的方法(失掉了一些行为)。
D.子类对象的上转型对象能调用子类新增的方法。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第18题:
下列哪个叙述是错误的?
A.abstract类也可以同时是final类。
B.如果一个抽象类是某个抽象类的子类,那么它可以将父类abstract方法重写为非abstract方法也可以不重写这个abstract方法(直接继承)。
C.子类对象的上转型对象不能操作子类新增的成员变量(失掉了这部分属性),不能调用子类新增的方法(失掉了一些行为)。
D.子类对象的上转型对象可以访问子类继承或隐藏的成员变量。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第19题:
下列哪个叙述是错误的?
A.abstract类不可以是final类。
B.abstract类声明的对象可以成为子类对象的上转型对象。
C.子类对象的上转型对象不能操作子类新增的成员变量(失掉了这部分属性),不能调用子类新增的方法(失掉了一些行为)。
D.abstract子类不继承abstrat父类的abstract方法 。

{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第20题:
下列哪个叙述是正确的?
A.源文件可以有2条包语句(package)。
B.源文件不可以有多条import语句。
C.如果源文件有package语句,该语句也可以是源文件的第2条语句。
D.类中的类方法(static方法)只能操作类变量(static变量),不可以操作实例变量。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第21题:
下列哪个叙述是错误的?
A.不可以用new运算符和abstract类的构造方法创建对象。
B.abstract类声明的对象可以成为子类对象的上转型对象。
C.abstract方法也可以同时是final方法。
D.除了java.lang.Object类外,任何类都有且仅有一个父类。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第22题:
下列哪个叙述是正确的?
A.任何一个类都可以有多个子类。
B.可以用new运算符和abstract类的构造方法创建对象。
C final 类不可以有父类。
D.面向抽象编程,是指当设计某种重要的类时,不让该类面向具体的类,而是面向抽象类,
即所设计类中的重要数据是抽象类声明的对象,而不是具体类声明的对象。
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第23题:
下列哪个叙述是正确的?
A. 编译器器不提示程序使用了空对象(让一个空对象去调用实例方法),但程序在运行时会出现NullPointerException异常。
B. 方法重载的意思是:一个类中可以有多个方法具有相同的名字,但这些方法的参数必须不同,并且返回类型必须相同。
C. static方法不可以重载。
D. 构造方法不可以重载。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第24题:
下列哪个叙述是正确的?
A.子类在方法重写时,可以把父类的实例方法重写为类(static)方法。
B.子类对象的上转型对象操作子类继承的方法或子类重写的实例方法,其作用等价于子类对象去调用这些方法。
C static方法也可以同时是abstract方法。
D.子类在方法重写时,可以把父类的类(static)方法重写为实例方法。
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第25题:
下列哪个叙述是正确的?
A.子类不可以声明和父类成员变量同名的成员变量。
B.可以用final修饰构造方法。
C.子类不继承父类的构造方法。
D.子类不可以定义和父类的方法同名的方法。
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第26题:
下列哪个叙述是错误的?
A.super关键字形成的语句必须是子类构造方法中的第1条语句。
B.如果在子类的构造方法中,显示地写出了super关键字来调用父类的某个构造方法,那么编译器不再提供默认的super语句。
C.子类构造方法中可以有多条super调用父类的某个构造方法的语句。
D.子类和父类不必在同一个包中。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第27题:
下列哪个叙述是正确的?
A.可以同时用finalabstract修饰一个类。
B.final类至多可以有一个子类。
C.子类可以用super关键字调用父类的父类中的方法。
D.子类和父类不必在同一个包中。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第28题:
下列哪个叙述是错误的?
A. abstract类中,必须要有abstract方法。
B abstract类中,也可以没有abstract方法。
C. 多态性就是指父类的某个方法被其子类重写时,可以各自产生自己的功能行为(多:子类数目,态:父类某个方法)。
D. 子类声明的成员的变量的名字和从父类继承来的成员变量的名字相同,子类就会隐藏掉所继承的成员变量。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第29题:
下列哪个叙述是正确的?
A. abstract类中,必须要有abstract方法。
B abstract方法的abstract关键字,必须放在方法的类型的前面,不可以插在方法类型和方法名字之间。
C. abstract类中不能有非abstract实例方法。
D. static方法也可以是abstract方法。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第30题:
下列哪个叙述是错误的?
A. 不允许同时用finalabstract修饰同一个方法。
B. 不允许同时用finalabstract修饰一个类。
C. 子类重写或新增的方法也能直接操作被子类隐藏的成员变量。
D. 子类继承的方法所操作的成员变量一定是被子类继承或隐藏的成员变量。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第31题:
下列哪个叙述是正确的?
A. 如果子类可以继承父类的某个方法,那么子类就有权利重写这个方法。
B. abstract类的子类必须是非abstract类。
C. 子类重写或新增的方法也能直接操作被子类隐藏的成员变量
D. abstract类中只可以有abstract方法。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第32题:
下列哪个叙述是正确的?
A. 一个Java源文件必须要有主类。
B. 类体中声明成员变量是为了体现对象的行为(功能)。
C. 可以把int型数据赋值给类声明的对象变量。
D. 类所声明的变量被称为对象,对象(变量)负责存放引用,以确保对象可以操作分配给该对象的变量以及调用类中的方法。分配给对象的变量被习惯地称做对象的实体。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10

题库中第33题:
下列哪个叙述是正确的?
A. 允许使用static修饰abstract方法。
B. 如果一个类的所有构造方法的访问权限都是private的,那么意味着这个类不能有子类。
(原因:一个类的private方法不能在其他类中被使用,但子类的构造方法中一定会调用父类的某个构造方法)"
C. 不能用final修饰构造方法。
D. 不能用static修饰构造方法。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10

题库中第34题:
下列哪个叙述是错误的?
A. 可以用public,protectedprivate修饰构造方法。
B. 子类在方法重写时,不可以把父类的类(static)方法重写为实例方法。
C. 子类在方法重写时,不可以把父类的实例方法重写为类(static)方法。
D. abstract类中,必须要有abstract方法。


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第35题:
下列哪个叙述是错误的?
A. 子类重写父类的方法时,不允许降低方法的访问权限,但可以提高访问权限。
B. 子类在方法重写时,可以把父类的public方法重写为private方法。
C. 子类在方法重写时,可以把父类的protected方法重写为public方法。
D. 如果成员变量被修饰为final的,就是常量,用户在声明时可以不指定该常量的值,编译器会提供默认的值。

{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第36题:
下列哪个叙述是错误的?
A. 如果一个非抽象类是某个抽象类的子类,那么它必须重写父类的抽象方法,即给出方法体(将abstract方法重写为非abstract方法)。
B. 如果一个抽象类是某个抽象类的子类,那么它可以将父类abstract方法重写为非abstract方法也可以不重写这个abstract方法(直接继承)。
C. abstract类不能实例化对象。
D. abstract类中不可以有非abstract方法。
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第37题:
下列哪个叙述是错误的?
A. 子类对象的上转型对象不能操作子类新增的成员变量(失掉了这部分属性),不能调用子类新增的方法(失掉了一些行为)。
B. 子类对象的上转型对象可以访问子类继承或隐藏的成员变量。
C. 子类对象的上转型对象操作子类继承的方法或子类重写的实例方法,其作用等价于子类对象去调用这些方法。
D. 子类对象的上转型对象是其父类创建的一个对象。
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第38题:
下列哪个叙述是正确的?
A. final 类不可以有父类。
B. 可以用new运算符和abstract类的构造方法创建对象。
C. 如果一个类中有abstract方法,这个类必须是abstract类。
D. static方法也可以同时是abstract方法。
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第39题:
下列哪个叙述是正确的?
A. final方法也可以同时是abstract方法
B. final类也可以同时是abstract类。
C. abstract方法也可以同时是final方法。
D. 不可以用new运算符和abstract类的构造方法创建对象
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第40题:
对于下列代码,叙述正确的是哪个?
class Animal{
int get(){
return 100;
}
}
class Dog extends Animal {
int get(){
return 88;
}
}
public class E {
public static void main(String args[]){
Animal dog = new Dog();
System.out.printf("%d",dog.get());
}
}
A.代码有编译错误。
B.运行输出100.
C.运行输出88.
D.无编译错误,但发生运行NullPointerException异常.
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第41题:
下列哪个叙述是正确的?
A. 子类继承的方法所操作的成员变量一定是被子类继承或隐藏的成员变量。
B. 子类和父类必须在一个包中。
C. final类至多可以有一个子类。
D. final类不能创建对象。
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第42题:
对于下列代码,叙述正确的是哪个?
class Animal{
int m =100;
int get(){
return m;
}
}
class Dog extends Animal {
int m = 2;

}
public class E {
public static void main(String args[]){
Animal dog = new Dog();
System.out.printf("%d",dog.get());
}
}
A.代码有编译错误。
B.运行输出2.
C.运行输出100.
D.无编译错误,但发生运行NullPointerException异常.
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第43题:
假设C是B的子类,B是A的子类,cat是C类的一个对象,bird是B类的一个对象,下列哪个叙述是错误的?
A. cat instanceof B的值是true
B. bird instanceof A的值是true
C. cat instanceof A的值是true
D. bird instanceof C的值是true
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第44题:
将下列哪个代码(A,B,C,D)放入程序中标注的【代码】处将导致编译错误?
A. public float getNum(){return 4.0f;}
B. public void getNum(){ }
C. public void getNum(double d){ }
D. public double getNum(float d){return 4.0d;}
class A {
public float getNum() {
return 3.0f;
}
}
public class B extends A {
【代码】
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第45题:
对于下列代码,下列哪个叙述是正确的?
A. 程序提示编译错误(原因是A类没有不带参数的构造方法)
B. 编译无错误,【代码】输出结果是0
C. 编译无错误,【代码】输出结果是1
D. 编译无错误,【代码】输出结果是2
class A {
public int i=0;
A(int m) {
i = 1;
}
}
public class B extends A {
B(int m) {
i = 2;
}
public static void main(String args[]){
B b = new B(100);
System.out.println(b.i); //【代码】
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第46题:
对于下列代码,下列哪个叙述是正确的?
A. 程序提示编译错误(Dog不是抽象的, 并且未覆盖,即重写Animal中的抽象方法f()).
B. 编译无错误,【代码】输出0
C. 编译无错误,【代码】输出100
D. 编译无错误,【代码】输出null
abstract class Animal {
int m =100;
abstract public void f();
}
class Dog extends Animal{
int m;
}
public class E {
public static void main(String args[]){
System.out.println(new Dog().m);//【代码】
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第47题:
下列哪些叙述是正确的(多选)?
A.用户在定义子类时,可以给子类指定多个父类。
B.除了java.lang.Object类,任何一个类有且仅有一个父类。
C.一个非final类可以有多个子类。
D.类声明class Aclass A extends Object是等价的。
{correctAnswer='BCD'}
1
2
3
4
5
6
7
8
9

题库中第48题:
下列哪些叙述是正确的(多选)?
A.java.lang包中的Object类是所有其他类的祖先类。
B.如果子类和父类不在同一个包中,子类不继承父类的友好成员。
C.所谓子类继承父类的成员变量作为自己的一个成员变量,就好象它们是在子类中直接声明一样,
可以被子类中自己定义的任何实例方法操作。
D.子类不可以声明和父类的成员变量同名的成员变量。
{correctAnswer='ABC'}
1
2
3
4
5
6
7
8

题库中第49题:
下列哪些叙述是错误的(多选)?
A.子类不可以声明和父类的成员变量同名的成员变量。
B.子类继承父类的构造方法。
C.子类不可以定义和父类的方法同名的方法。
D.子类不继承父类的构造方法。
{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9

题库中第50题:
下列哪些叙述是正确的(多选)?
A.可以用final修饰构造方法。
B.可以用static修饰构造方法。
C.如果在子类的构造方法中,没有显示地写出super关键字来调用父类的某个构造方法,那么编译器默认地有:
super();调用父类的无参数的构造方法(如果父类没有这样的构造方法,代码将出现编译错误)。"
D.super关键字形成的语句必须是子类构造方法中的第1条语句。
{correctAnswer='CD'}
1
2
3
4
5
6
7
8

题库中第51题:
下列哪些叙述是错误的(多选)?
A.如果在子类的构造方法中,显示地写出了super关键字来调用父类的某个构造方法,那么编译器不再提供默认的super语句。
B.子类构造方法中可以有多条super调用父类的某个构造方法的语句。
C.子类和父类必须在一个包中。
D.final类至多可以有一个子类。
{correctAnswer='BCD'}
1
2
3
4
5
6
7
8

题库中第52题:
下列哪些叙述是错误的(多选)?
A.可以同时用finalabstract修饰同一个方法。
B.可以同时用finalabstract修饰一个类。
C.abstract类中,必须要有abstract方法。
D.abstract类中,也可以没有abstract方法。
{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9

题库中第53题:
下列哪些叙述是正确的(多选)?
A.子类声明的成员的变量的名字和从父类继承来的成员变量的名字相同,子类就会隐藏掉所继承的成员变量。
方法的修饰(如果有),例如public,abstract,必须放在方法的类型的前面,不可以插在方法类型和方法名字之间。
B.abstract类中不能有非abstract实例方法。
C.不允许同时用staticabstract修饰同一方法。
D.abstract类的子类必须是非abstract类。
{correctAnswer='AC'}
1
2
3
4
5
6
7
8
9

题库中第54题:
下列哪些叙述是正确的(多选)?
A.子类在方法重写时,可以把父类的类(static)方法重写为实例方法。
B.子类重写父类的方法时,不允许降低方法的访问权限,但可以提高访问权限
.
C.子类在方法重写时,可以把父类的public方法重写为private方法。
D.子类在方法重写时,可以把父类的protected方法重写为public方法。
{correctAnswer='BD'}
1
2
3
4
5
6
7
8

题库中第55题:
下列哪些叙述是正确的(多选)?
A.子类对象的上转型对象可以访问子类继承或隐藏的成员变量。
B.子类对象的上转型对象操作子类继承的方法或子类重写的实例方法,其作用等价于子类对象去调用这些方法。
C.子类对象的上转型对象不能操作子类新增的成员变量。
D.任何一个类都可以有多个子类。
{correctAnswer='ABC'}
1
2
3
4
5
6
7
8

题库中第56题:
下列哪些叙述是正确的(多选)?
A.如果成员变量被修饰为final的,就是常量,用户在声明时可以不指定该常量的值,编译器会提供默认的值。
B.如果一个非抽象类是某个抽象类的子类,那么它必须重写父类的抽象方法,即给出方法体(将abstract方法重写为非abstract方法)。
C.可以用public,protectedprivate修饰构造方法。
D.abstract类也可以同时是final类。
{correctAnswer='BC'}

判断题

1
2
3
4

题库中第1题:
用户在定义子类时,可以给子类指定多个父类。
{correctAnswer='错误'}
1
2
3
4

题库中第2题:
除了java.lang.Object类,任何一个类有且仅有一个父类。
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
一个非final类可以有多个子类。
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
类声明class Aclass A extends Object是等价的。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
java.lang包中的Object类是所有其他类的祖先类。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
如果子类和父类不在同一个包中,子类不继承父类的友好成员。
{correctAnswer='正确'}
1
2
3
4
5

题库中第7题:
所谓子类继承父类的成员变量作为自己的一个成员变量,就好象它们是在子类中直接声明一样,
可以被子类中自己定义的任何实例方法操作。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
如果在子类中想使用被子类隐藏的实例成员变量或实例方法就需要使用关键字super
{correctAnswer='正确'}
1
2
3
4

题库中第9题:
子类不可以声明和父类的成员变量同名的成员变量。
{correctAnswer='错误'}
1
2
3
4

题库中第10题:
子类继承父类的构造方法。
{correctAnswer='错误'}
1
2
3
4

题库中第11题:
子类不可以定义和父类的方法同名的方法。
{correctAnswer='错误'}
1
2
3
4

题库中第12题:
子类不继承父类的构造方法。
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
可以用final修饰构造方法。
{correctAnswer='错误'}
1
2
3
4

题库中第14题:
可以用static修饰构造方法。
{correctAnswer='错误'}
1
2
3
4
5

题库中第15题:
如果在子类的构造方法中,没有显示地写出super关键字来调用父类的某个构造方法,那么编译器默认地有:
super();调用父类的无参数的构造方法(如果父类没有这样的构造方法,代码将出现编译错误)。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
super关键字形成的语句必须是子类构造方法中的第1条语句。
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
如果在子类的构造方法中,显示地写出了super关键字来调用父类的某个构造方法,那么编译器不再提供默认的super语句。
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
子类构造方法中可以有多条super调用父类的某个构造方法的语句。
{correctAnswer='错误'}
1
2
3
4

题库中第19题:
子类和父类必须在一个包中。
{correctAnswer='错误'}
1
2
3
4

题库中第20题:
final类至多可以有一个子类。
{correctAnswer='错误'}
1
2
3
4

题库中第21题:
final类不能被继承,即不能有子类。
{correctAnswer='正确'}
1
2
3
4

题库中第22题:
可以同时用finalabstract修饰同一个方法。
{correctAnswer='错误'}
1
2
3
4

题库中第23题:
可以同时用finalabstract修饰一个类。
{correctAnswer='错误'}
1
2
3
4

题库中第24题:
abstract类中,必须要有abstract方法。
{correctAnswer='错误'}
1
2
3
4

题库中第25题:
abstract类中,也可以没有abstract方法。
{correctAnswer='正确'}
1
2
3
4

题库中第26题:
多态性就是指父类的某个方法被其子类重写时,可以各自产生自己的功能行为(多:子类数目,态:父类某个方法)。
{correctAnswer='正确'}
1
2
3
4

题库中第27题:
子类声明的成员的变量的名字和从父类继承来的成员变量的名字相同,子类就会隐藏掉所继承的成员变量。
{correctAnswer='正确'}
1
2
3
4

题库中第28题:
方法的修饰(如果有),例如public,abstract,必须放在方法的类型的前面,不可以插在方法类型和方法名字之间。
{correctAnswer='正确'}
1
2
3
4

题库中第29题:
abstract类中不能有非abstract实例方法。
{correctAnswer='错误'}
1
2
3
4

题库中第30题:
不允许同时用staticabstract修饰同一方法。
{correctAnswer='正确'}
1
2
3
4

题库中第31题:
子类可以用super关键字调用父类的父类中的方法。
{correctAnswer='错误'}
1
2
3
4

题库中第32题:
不允许同时用finalabstract修饰同一个方法。
{correctAnswer='正确'}
1
2
3
4

题库中第33题:
不允许同时用finalabstract修饰一个类。
{correctAnswer='正确'}
1
2
3
4

题库中第34题:
子类重写或新增的方法也能直接操作被子类隐藏的成员变量。
{correctAnswer='错误'}
1
2
3
4

题库中第35题:
子类继承的方法所操作的成员变量一定是被子类继承或隐藏的成员变量。
{correctAnswer='正确'}
1
2
3
4

题库中第36题:
如果子类可以继承父类的某个方法,那么子类就有权利重写这个方法。
{correctAnswer='正确'}
1
2
3
4

题库中第37题:
abstract类的子类必须是非abstract类。
{correctAnswer='错误'}
1
2
3
4

题库中第38题:
子类重写或新增的方法也能直接操作被子类隐藏的成员变量
{correctAnswer='错误'}
1
2
3
4

题库中第39题:
abstract类中只可以有abstract方法。
{correctAnswer='错误'}
1
2
3
4

题库中第40题:
允许使用static修饰abstract方法。
{correctAnswer='错误'}
1
2
3
4
5

题库中第41题:
如果一个类的所有构造方法的访问权限都是private的,那么意味着这个类不能有子类
(原因:一个类的private方法不能在其他类中被使用,但子类的构造方法中一定会调用父类的某个构造方法)。
{correctAnswer='正确'}
1
2
3
4

题库中第42题:
不能用final修饰构造方法。
{correctAnswer='正确'}
1
2
3
4

题库中第43题:
不能用static修饰构造方法。
{correctAnswer='正确'}
1
2
3
4

题库中第44题:
可以用public,protectedprivate修饰构造方法。
{correctAnswer='正确'}
1
2
3
4

题库中第45题:
子类在方法重写时,不可以把父类的类(static)方法重写为实例方法。
{correctAnswer='正确'}
1
2
3
4

题库中第46题:
子类在方法重写时,不可以把父类的实例方法重写为类(static)方法。
{correctAnswer='正确'}
1
2
3
4

题库中第47题:
子类在方法重写时,可以把父类的实例方法重写为类(static)方法。
{correctAnswer='错误'}
1
2
3
4

题库中第48题:
子类在方法重写时,可以把父类的类(static)方法重写为实例方法。
{correctAnswer='错误'}
1
2
3
4
5

题库中第49题:
子类重写父类的方法时,不允许降低方法的访问权限,但可以提高访问权限
(访问限制修饰符按访问权限从高到低的排列顺序是:publicprotected、友好的、private
{correctAnswer='正确'}
1
2
3
4

题库中第50题:
子类在方法重写时,可以把父类的public方法重写为private方法。
{correctAnswer='错误'}
1
2
3
4

题库中第51题:
子类在方法重写时,可以把父类的protected方法重写为public方法。
{correctAnswer='正确'}
1
2
3
4

题库中第52题:
如果子类是abstract类,允许子类将父类的非abstract方法重写为abstract方法。
{correctAnswer='正确'}
1
2
3
4

题库中第53题:
如果一个非抽象类是某个抽象类的子类,那么它必须重写父类的抽象方法,即给出方法体(将abstract方法重写为非abstract方法)。
{correctAnswer='正确'}
1
2
3
4

题库中第54题:
如果一个抽象类是某个抽象类的子类,那么它可以将父类abstract方法重写为非abstract方法也可以不重写这个abstract方法(直接继承)。
{correctAnswer='正确'}
1
2
3
4

题库中第55题:
子类对象的上转型对象不能操作子类新增的成员变量(失掉了这部分属性),不能调用子类新增的方法(失掉了一些行为)。
{correctAnswer='正确'}
1
2
3
4

题库中第56题:
子类对象的上转型对象可以访问子类继承或隐藏的成员变量。
{correctAnswer='正确'}
1
2
3
4

题库中第57题:
子类对象的上转型对象操作子类继承的方法或子类重写的实例方法,其作用等价于子类对象去调用这些方法。
{correctAnswer='正确'}
1
2
3
4

题库中第58题:
子类对象的上转型对象不能操作子类新增的成员变量。
{correctAnswer='正确'}
1
2
3
4

题库中第59题:
子类对象的上转型对象不能操作不能调用子类新增的方法。
{correctAnswer='正确'}
1
2
3
4
5

题库中第60题:
面向抽象编程,是指当设计某种重要的类时,不让该类面向具体的类,而是面向抽象类,
即所设计类中的重要数据是抽象类声明的对象,而不是具体类声明的对象。
{correctAnswer='正确'}
1
2
3
4

题库中第61题:
如果成员变量被修饰为final的,就是常量,用户在声明时必须指定该常量的值。
{correctAnswer='正确'}
1
2
3
4

题库中第62题:
如果成员变量被修饰为final的,就是常量,用户在声明时可以不指定该常量的值,编译器会提供默认的值。
{correctAnswer='错误'}
1
2
3
4

题库中第63题:
子类对象的上转型对象也能操作子类新增的成员变量。
{correctAnswer='错误'}
1
2
3
4

题库中第64题:
子类对象的上转型对象也能调用子类新增的方法。
{correctAnswer='错误'}
1
2
3
4

题库中第65题:
abstract类也可以同时是final类。
{correctAnswer='错误'}
1
2
3
4

题库中第66题:
final类也可以同时是abstract类。
{correctAnswer='错误'}
1
2
3
4

题库中第67题:
abstract方法也可以同时是final方法。
{correctAnswer='错误'}
1
2
3
4

题库中第68题:
final方法也可以同时是abstract方法。
{correctAnswer='错误'}
1
2
3
4

题库中第69题:
static方法也可以同时是final方法。
{correctAnswer='正确'}
1
2
3
4

题库中第70题:
final方法也可以同时是static方法。
{correctAnswer='正确'}
1
2
3
4

题库中第71题:
static方法也可以同时是abstract方法。
{correctAnswer='错误'}
1
2
3
4

题库中第72题:
abstract方法也可以同时是static方法。
{correctAnswer='错误'}
1
2
3
4

题库中第73题:
除了java.lang.Object类外,任何类都有且仅有一个父类。
{correctAnswer='正确'}
1
2
3
4

题库中第74题:
任何一个类都可以有多个子类。
{correctAnswer='错误'}
1
2
3
4

题库中第75题:
final 类不可以有父类。
{correctAnswer='错误'}
1
2
3
4

题库中第76题:
可以用new运算符和abstract类的构造方法创建对象。
{correctAnswer='错误'}
1
2
3
4

题库中第77题:
如果一个类中有abstract方法,这个类必须是abstract类。
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
class Animal{
int m =100; //A
}
class Dog extend Animal //B
{
}
class Cat extends Animal //C
{
}
public class E {
public static void main(String args[]){
Animal cat = new Cat(); //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
class A {
static int m;
static void f(){
m = 20 ; //A
}
}
class B extends A {
void f() //B
{ m = 222 ; //C
}
}
class E {
public static void main(String args[]) {
A.f(); // D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
class A {
static int m;
void f(){
m = 20 ; //A
}
}
class B extends A {
static void f() //B
{ m = 222 ; //C
}
}
class E {
public static void main(String args[]) {
B.m = 10; // D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
class Animal extends Object //A
{
int m =100;
void Animal(){
m = 20;
}
Animal(int m){
this.m = m; //B
}
}
class Dog extends Animal{
Dog(){
super(); //C
}
Dog(int m){
super(m); //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
class Father {
private int money =12;
float height;
int seeMoney(){
return money ; //A
}
}
class Son extends Father {
int height;
int lookMoney() {
int m = seeMoney(); //B
return m;
}
}
class E {
public static void main(String args[]) {
Son erzi = new Son();
erzi.money = 300; //C
erzi.height = 1.78F; //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第6题:
下列ABCD注释标注的哪行代码有错误?
class Father {
private int money =12;
float height;
int seeMoney(){
return money ; //A
}
}
class Son extends Father {
int m;
void f() {
m = seeMoney(); //B
m = money; //C
height = m+12.7F; //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10

题库中第7题:
下列ABCD注释标注的哪行代码有错误?
abstract class Takecare {
protected void speakHello() {} //A
public abstract static void cry(); //B
static int f(){ return 0 ;} //C
abstract float g(); //D
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10

题库中第8题:
下列ABCD注释标注的哪行代码有错误?
class Hello {
protected void speakHello() {} //A
public abstract void cry(); //B
static int f(){ return 0 ;} //C
void start(){ } //D
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10

题库中第9题:
下列ABCD注释标注的哪行代码有错误?
abstract class AAA {
final static void speakHello() {} //A
final abstract void cry(); //B
static final int f(){ return 0 ;} //C
abstract float g(); //D
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第10题:
下列ABCD注释标注的哪行代码有错误?
class Animal {
protected void cry(){}
}
class Dog extends Animal {
void cry() //A
{}
void cry(int m) //B
{}
}
class Cat extends Animal {
public void cry() //C
{}
void cry(int m,int n) //D
{}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第11题:
下列ABCD注释标注的哪行代码有错误?
class Animal {
void cry(){}
}
class Dog extends Animal {
protected void cry() //A
{}
void cry(int m) //B
{}
}
class Cat extends Animal {
private void cry() //C
{}
void cry(int m,int n) //D
{}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第12题:
下列ABCD注释标注的哪行代码有错误?
class A {
float computer(float x,float y) //A
{
return x+y;
}
int g(int x,int y) //B
{
return x+y;
}
}
class B extends A {
double computer(float x,float y) //C
{
return x*y;
}
public int g(int x,int y) //D
{
return x-y;
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第13题:
下列ABCD注释标注的哪行代码有错误?
class Tom {
private int x = 120;
protected int y = 20;
int z = 11;
private void showX() {
System.out.println(x);
}
public void setX(int x) {
this.x = x;
System.out.println(x);
}
}
public class E {
public static void main(String args[]) {
Tom tom = new Tom();
tom.setX(22); //A
tom.y = 33; //B
tom.z = 55; //C
tom.showX(); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

题库中第14题:
下列ABCD注释标注的哪行代码有错误?
abstract class Animal {
void cry(){}
}
class Dog extends Animal {
}
class Cat extends Animal {
}
class GetAnimal {
Animal get() {
return null; //A
}
}
class GetDog extends GetAnimal {
Dog get() //B
{
return new Dog();
}
}
class GetCat extends GetAnimal {
Cat get() //C
{
return new Cat();
}
}
class Other extends GetAnimal {
Animal get()
{
return new Animal(); //D
}
}










{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第15题:
下列ABCD注释标注的哪行代码有错误?
abstract class A {
abstract float getFloat (); //A
void f() //B
{}
}
class B extends A {
private float m = 1.0f; //C
private float getFloat () //D
{ return m;
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第16题:
下列ABCD注释标注的哪行代码有错误?
class A {
public float getNum() {
return 3.0f;
}
}
class B extends A {
public void getNum() //A
{}
public float getNum(int x) //B
{
return 3.14f+x;
}
public void getNum(double d) //C
{}
public double getNum(float d) //D
{
return 5.8+d;
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第17题:
下列ABCD注释标注的哪行代码有错误?
class Animal {
int m =100;
Animal(){
m = 20;
}
Animal(int m){
this.m = m; //A
}
}
class Dog extends Animal{
Dog(){
m = 100;
super(2); //B
}
Dog(int m){
super(); //C
this.m = m ; //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第18题:
下列ABCD注释标注的哪行代码有错误?
abstract class Animal {
int m =100;
}
class Dog extends Animal{
double m;
}
public class E {
public static void main(String args[]){
Animal animal = null; //A
Dog dog = new Dog();
animal = dog; //B
dog.m = 3.14; //C
animal.m = 3.14; //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第19题:
下列ABCD注释标注的哪行代码有错误?
abstract class Animal {
double m =100;
}
class Dog extends Animal{
int m;
}
public class E {
public static void main(String args[]){
Animal animal = null; //A
Dog dog = new Dog();
animal = dog; //B
dog.m = 3.14; //C
animal.m = 3.14; //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第20题:
下列ABCD注释标注的哪行代码有错误?
abstract class Animal {
abstract void f();
}
class Dog extends Animal{
public void f(){}
public void g(){}
}
public class E {
public static void main(String args[]){
Animal animal = null;
Dog dog = new Dog(); //A
animal = dog ; //B
animal.f() ; //C
animal.g(); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第21题:
下列ABCD注释标注的哪行代码有错误?
class A {
int f(int x,int y) {
return x+y;
}
}
class B extends A {
int f(double x,int y) {
return (int)x*y;
}
}
public class E {
public static void main(String args[]) {
B b=new B();
int m = b.f(3,5); //A
m = b.f(3.14,5); //B
A a = b;
m = a.f(3,5); //C
m = a.f(3.14,5); //D
}
}
{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
class Animal {
private int m = 100;
public int setM(){
return m;
}
}
class Dog extends Animal{
int m = 65;
public int getM(){
return m;
}
}
public class E {
public static void main(String args[]){
Dog dog = new Dog();
System.out.printf("%d:%d",dog.setM(),dog.getM());//【代码】

}
}
{correctAnswer='100:65'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
class Animal {
int m = 100;
public int setM(){
return m;
}
}
class Dog extends Animal{
double m = 3.14;
}
public class E {
public static void main(String args[]){
Dog dog = new Dog();
System.out.printf("%d",dog.setM());
}
}
{correctAnswer='100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
class Animal {
int m = 100;
public int setM(){
return m;
}
}
class Dog extends Animal{
int m = 6;
public int setM(){
return m;
}
}
public class E {
public static void main(String args[]){
Dog dog = new Dog();
System.out.printf("%d",dog.setM()); //【代码】
}
}
{correctAnswer='6'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
class Animal {
int m = 100;
public int setM(){
return m;
}
}
class Dog extends Animal{
int m = 6;
public int setM(){
return m;
}
}
public class E {
public static void main(String args[]){
Animal dog = new Dog();
System.out.printf("%d:%d",dog.setM(),dog.m); //【代码】
}
}
{correctAnswer='6:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
class Animal {
int m = 100;
public int setM(){
return m;
}
public int getM(){
return m;
}
}
class Dog extends Animal{
int m = 6;
public int setM(){
return m;
}
}
public class E {
public static void main(String args[]){
Animal dog = new Dog();
System.out.printf("%d:%d",dog.setM(),dog.getM()); //【代码】
}
}
注解:子类继承的方法中操作的成员变量m一定是继承的或者被子类隐藏的m。子类新增或重写的方法中操作的m一定是子类声明的那个m.
{correctAnswer='6:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
class Animal{
int m;
Animal(){
m = 100;
}
Animal(int m) {
this.m = m;
}
}
class Dog extends Animal {
Dog() {
super(8);
m += 10;
}
}
public class E {
public static void main(String args[]){
Dog dog = new Dog();
System.out.println(dog.m); //【代码】
}
}

{correctAnswer='18'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
class Animal{
int m;
Animal(){
m = 100;
}
Animal(int m) {
this.m = m;
}
}
class Dog extends Animal {
Dog() {
m += 10;
}
}
public class E {
public static void main(String args[]){
Dog dog = new Dog();
System.out.println(dog.m); //【代码】
}
}
{correctAnswer='110'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第8题:
给出下列【代码】注释标注的代码的输出结果。
class Animal{
int m = 100;
}
class Dog extends Animal {
double m;
public void setM(){
m = super.m+3.14;
}
}
public class E {
public static void main(String args[]){
Dog dog = new Dog();
dog.setM();
System.out.println(dog.m); //【代码】
}
}
{correctAnswer='103.14'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第9题:
给出下列【代码】注释标注的代码的输出结果。
class Animal{
public int get(int n){
return n;
}
}
class Dog extends Animal {
public int get(int n){
return n+super.get(n);
}
}
class Cat extends Animal {
public int get(int n){
return n*super.get(n);
}
}
public class E {
public static void main(String args[]){
Animal animal = new Dog();
int m = animal.get(10);
animal = new Cat();
int n = animal.get(10);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='20:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第10题:
给出下列【代码】注释标注的代码的输出结果。
class Animal{
public int get(int n){
return n;
}
}
class Dog extends Animal {
public int get(int n){
return n+super.get(n);
}
}
public class E {
public static void main(String args[]){
Animal animal = new Animal();
int m =animal.get(10);
animal = new Dog();
int n =animal.get(10);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='10:20'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第11题:
给出下列【代码】注释标注的代码的输出结果。
class Animal{
public int get(int n){
return n;
}
}
class Dog extends Animal {
public int get(int n){
return n+8;
}
}
public class E {
public static void main(String args[]){
Animal animal = new Animal();
int m =animal.get(10);
animal = new Dog();
int n =animal.get(10);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='10:18'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

题库中第12题:
给出下列【代码】注释标注的代码的输出结果。
class Animal{
int m = 9;
public int get(int n){
return n+m;
}
public int see(int n){
return n+m;
}
}
class Dog extends Animal {
int m = 18;
public int get(int n){
return n+m;
}
}
public class E {
public static void main(String args[]){
Animal animal = null;
Dog dog = new Dog();
animal = dog;
animal.m = 19;
dog.m = 88;
int result1 =animal.see(10);
int result2 =animal.get(10);
System.out.printf("%d:%d",result1,result2); //【代码】
}
}
注解:知识点细节见教材5.7节。上转型对象操作的m,animal.m一定是子类隐藏的m。上转型调用的继承的方法see(int n)操作的m一定是子类隐藏的m。dog的上转型对象animal调用的get方法一定是子类重写的get方法,等价子类对象dog去调用。
{correctAnswer='29:98'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第13题:
给出下列【代码】注释标注的代码的输出结果。
class Lake {
Fish fish;
void setFish(Fish s){
fish = s;
}
void foodFish(int m) {
fish.weight=fish.weight+m;
}
Fish getFish(){
fish.weight -= 10;
return fish;
}
}
public class E {
public static void main(String args[]) {
Fish redFish = new Fish();
Lake lake = new Lake();
lake.setFish(redFish);
lake.foodFish(120);
int w = lake.fish.weight;
Fish fishOK = lake.getFish();
System.out.printf("%d:%d:%d",w,lake.fish.weight,fishOK.weight); //【代码】
}
}
{correctAnswer='121:111:111'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第14题:
给出下列【代码】注释标注的代码的输出结果。
class Animal{
public static int get(int n){
return n+10;
}
public int see(int n){
return n+10;
}
}
class Dog extends Animal {
public static int get(int n){
return n*10;
}
public int see(int n){
return n*10;
}
}
public class E {
public static void main(String args[]){
Animal animal = null;
animal = new Dog();
System.out.printf("%d:%d",animal.get(10),animal.see(10)); //【代码】
}
}
注解:知识点见教材java2实用教程微课版5.7节中的注。
{correctAnswer='20:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第15题:
给出下列【代码】注释标注的代码的输出结果。
class University {
public int getScore(){
return 410;
}
}
class Beijing extends University {
public int getScore(){
return 210+super.getScore();
}
}
class Shanghai extends University {
public int getScore(){
return 220+super.getScore();
}
}
public class E {
public static void main(String args[]){
University u = new Beijing();
int m = u.getScore();
u = new Shanghai();
int n = u.getScore();
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='620:630'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第16题:
给出下列【代码】注释标注的代码的输出结果。
class A {
int f(int x,int y) {
return x+y;
}
}
class B extends A {
int f(double x,int y) {
return (int)x*y;
}
}
public class E {
public static void main(String args[]) {
B b=new B();
int m = b.f(3,5);
int n = b.f(3.14,5);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='8:15'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第17题:
给出下列【代码】注释标注的代码的输出结果。
class A {
int f(int x,int y) {
return x+y;
}
}
class B extends A {
int f(double x,int y) {
return (int)x*y;
}
}
public class E {
public static void main(String args[]) {
B b=new B();
int m = b.f(3,5);
A a = b;
int n = a.f(3,5);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='8:8'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第18题:
给出下列【代码】注释标注的代码的输出结果。
class A {
public int getNumber(int a) {
return a+1;
}
}
class E extends A {
public int getNumber (int a) {
return a+100;
}
public static void main (String args[]) {
A a = new A();
int m = a.getNumber(10);
a = new E();
int n = a.getNumber(10);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='11:110'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第19题:
给出下列【代码】注释标注的代码的输出结果。
class A {
int f(int x,int y) {
return x+y;
}
}
class B extends A {
int f(int x,int y) {
int m = super.f(x,y)+10;
return m;
}
}
public class E {
public static void main(String args[]) {
A a = new B();
System.out.println(a.f(2,10)); //【代码】
}
}
{correctAnswer='22'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

题库中第20题:
给出下列【代码】注释标注的代码的输出结果。
class A {
int f(int x,int y) {
return x+y;
}
static int g(int n) {
return n*n;
}
}
class B extends A {
int f(int x,int y) {
int m = super.f(x,y)+x*y;
return m;
}
static int g(int n) {
int m = A.g(n)+n;
return m;
}
}
public class E {
public static void main(String args[]) {
A a = new B();
int m = a.f(10,8);
int n = a.g(3);
System.out.printf("%d:%d",m,n); //【代码】
}
}
{correctAnswer='98:9'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

题库中第21题:
给出下列【代码】注释标注的代码的输出结果。
class A {
int m;
int getM() {
return m;
}
int seeM() {
return m;
}
}
class B extends A {
int m ;
int getM() {
return m+100;
}
}
public class E {
public static void main(String args[]) {
B b = new B();
b.m = 20;
int num1 = b.getM();
A a = b;
a.m = 100;
int num2 = a.getM();
int num3 = a.seeM();
System.out.printf("%d:%d:%d",num1,num2,num3);
}
}
注解:细节见教材5.7节.b的上转型对象a访问的是被隐藏的m,b的上转型对象a调用的一定是子类重写的getM()方法
子类继承的seeM()方法操作的m是被子类隐藏的m
{correctAnswer='120:120:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第22题:
给出下列【代码】注释标注的代码的输出结果。
class Animal {
int m = 100;
public int seeM(){
return m;
}
public int getM(){
return m;
}
}
class Dog extends Animal{
int m = 6;
public int seeM(){
return m;
}
}
public class E {
public static void main(String args[]){
Animal animal = null;
Dog dog = new Dog();
animal = dog;
System.out.printf("%d:%d:%d",dog.seeM(),animal.seeM(),animal.getM()); //【代码】
}
}
注解:子类继承的方法中操作的成员变量m一定是继承的或者被子类隐藏的m。子类新增或重写的方法中操作的m一定是子类声明的那个m.
{correctAnswer='6:6:100'}

第6章

选择题

1
2
3
4
5
6
7
8
9
10

题库中第1题:
下列哪个叙述是正确的?
A. 一个类最多可以实现两个接口。
B.如果一个抽象类实现某个接口,那么它必须要重写接口中的全部方法。
C.如果一个非抽象类实现某个接口,那么它可以只重写接口中的部分方法。
D.允许接口中只有一个抽象方法。


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第2题:
下列哪个叙述是正确的?
A.能用public修饰接口。
B.能用protected修饰接口。
C.能用final修饰接口。
D.能用private修饰接口。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第3题:
对于下列Com接口(Com.java)类,哪个叙述是正确的?
interface Com {
int MAX = 100;
int f();
}

A.Com是一个public接口。
B.编译器认为int MAX = 100;就是 public static final int MAX = 100;
C.编译器认为int f();就是abstract int f();
D.编译器认为int MAX = 100;就是 public final int MAX = 100;

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第4题:
对于下列代码,哪个叙述是正确的?
interface Com {
int MAX = 100;
public void stop();
protected void start();
abstract void loop();
}

A. protected void start();会导致编译出错。
B. public void stop(;会导致编译出错。
C abstract void loop();会导致编译出错。
D. int MAX = 100;会导致编译出错。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第5题:
对于下列代码,下列哪个叙述是错误的?
interface Com {
int MAX = 100;
void stop();
abstract void start();
}

A.void stop();会导致编译出错。
B.编译器认为 void stop();就是public abstract void stop();
C 编译器认为 abstract void start();就是public abstract void start();
D.编译器认为 int MAX = 100;就是 public static final int MAX = 100;

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第6题:
对于下列代码,下列哪个叙述是错误的?
interface Com {
int MAX ;
void stop();
abstract void start();
}

A.Com是个友好接口。
B.编译器认为 void stop();就是public abstract void stop();
C 编译器认为 abstract void start();就是public abstract void start();
D.int MAX ;不会导致编译错误。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第7题:
下列哪个叙述是错误的?
A.如果一个非abstract类实现某个接口,该类必须重写接口中的全部abstract方法。
B.可以用接口名直接访问接口中的常量。
C.不能用final修饰接口。
D.能用protected 修饰接口。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第8题:
下列哪些叙述是正确的?(多选)
A.如果一个非abstract类实现某个接口,该类必须重写接口中的全部abstract方法。
B.可以用接口名直接访问接口中的常量。
C.能用abstract修饰接口。
D.能用private 修饰接口。

{correctAnswer='ABC'}
1
2
3
4
5
6
7
8

题库中第9题:
下列哪个叙述是错误的?
A. 类声明class A implements Printable,Addable意思是A类实现Prinabe和Addable两个接口。
B. 类声明class Stu extends People implements Com 意思是Stu类是People类的子类,同时实现Com接口。
C. 类声明class Stu extends People implements Com 意思是Stu类是People类的子类,父类People实现Com接口。
D. inferfce Com1 extends Com2 意思是Com1是Com2的子接口。
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第10题:
下列哪些叙述是正确的?(多选)
A. 类声明class A implements Printable,Addable意思是A类实现Prinabe和Addable两个接口。
B. 类声明class Stu extends People implements Com 意思是Stu类是People类的子类,同时实现Com接口。
C. 类声明class Stu extends People implements Com 意思是Stu类是People类的子类,父类People实现Com接口。
D. inferfce Com1 extends Com2 意思是Com1是Com2的子接口。
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9
10

题库中第11题:
下列哪个叙述是错误的?
A. 一个类声明实现一个接口,但没有重写接口中的所有方法,那么这个类必须是抽象类。
B. 子接口将继承父接口中的全部方法和常量。
C. 接口也是Java中一种重要数据类型,用接口声明的变量称做接口变量。
D. 可以把一个int数据赋值给接口变量。


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第12题:
下列哪些叙述是正确的?(多选)
A. 一个类声明实现一个接口,但没有重写接口中的所有方法,那么这个类必须是抽象类。
B. 子接口将继承父接口中的全部方法和常量。
C. 接口变量中可以存放实现该接口的类的实例的引用(对象的引用)。
D. 可以把一个int数据赋值给接口变量。

{correctAnswer='ABC'}
1
2
3
4
5
6
7
8

题库中第13题:
对于下列代码,下列哪个叙述是错误的?
A.把实现某一接口的类创建的对象的引用赋值给该接口变量,那么该接口变量就可以调用被类实现的接口方法。
B.接口中只可以有常量,不能有变量。
C.接口中的方法可以用privateprotected修饰。
D.abstract类中既可以有常量也可以有变量。
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第14题:
下列哪些叙述是正确的?(多选)
A.把实现某一接口的类创建的对象的引用赋值给该接口变量,那么该接口变量就可以调用被类实现的接口方法。
B.接口中只可以有常量,不能有变量。
C.接口中的方法可以用privateprotected修饰。
D.abstract类中既可以有常量也可以有变量。
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9

题库中第15题:
下列哪些叙述是正确的?(多选)
A.接口中的常量可以不指定初值,编译器会提供默认值。
B.接口中的常量必须指定初值。
C.可以用abstract修饰接口。
D.可以用private或proteced修饰接口。

{correctAnswer='BC'}
1
2
3
4
5
6
7
8
9

题库中第16题:
下列哪些叙述是错误的?(多选)
A.接口中的常量可以不指定初值,编译器会提供默认值。
B.接口中的常量必须指定初值。
C.可以用abstract修饰接口。
D.可以用private或proteced修饰接口。

{correctAnswer='AD'}
1
2
3
4
5
6
7
8
9

题库中第17题:
下列哪个叙述是正确的?
A. 一个接口可以继承多个接口。
B. 可以用final修饰接口中的方法。
C. 接口默认是public接口。
D. public类只能实现public接口,不能实现友好接口。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第18题:
下列哪些叙述是错误的?(多选)
A. 一个接口可以继承多个接口。
B. 可以用final修饰接口中的方法。
C. 接口默认是public接口。
D. public类只能实现public接口,不能实现友好接口。

{correctAnswer='BCD'}
1
2
3
4
5
6
7
8
9

题库中第19题:
下列哪些叙述是错误的?(多选)
A. 类和它所实现的接口不一定在同一个包里。
B. abstract类不能实现任何接口。
C. 一个类至多可实现一个接口。
D. 一个类不能重复实现同一个接口,例如class A implements Com,Com

{correctAnswer='BC'}
1
2
3
4
5
6
7
8

题库中第20题:
下列哪些叙述是正确的?(多选)
A. 类和它所实现的接口不一定在同一个包里。
B. abstract类不能实现任何接口。
C. 一个类至多可实现一个接口。
D. 一个类不能重复实现同一个接口,例如class A implements Com,Com
{correctAnswer='AD'}
1
2
3
4
5
6
7
8
9

题库中第21题:
下列哪些叙述是错误的?(多选)
A. final类不能实现任何接口。
B. public接口可以被任何一个类实现。
C. 友好类和它所实现的接口必须在一个包里。
D. 如果一个类和友好接口在同一个包里,就允许它实现该接口。

{correctAnswer='AC'}
1
2
3
4
5
6
7
8

题库中第22题:
下列哪想叙述是正确的?(多选)
A. final类不能实现任何接口。
B. public接口可以被任何一个类实现。
C. 友好类和它所实现的接口必须在一个包里。
D. 如果一个类和友好接口在同一个包里,就允许它实现该接口。
{correctAnswer='BD'}
1
2
3
4
5
6
7
8

题库中第23题:
下列哪些叙述是正确的?(多选)
A.允许public类实现任何友好接口。
B.任何一个类都可以实现public接口。
C.如果一个类和友好接口在同一个包里,就允许它实现该接口。
D.接口变量中可以存放任何对象的引用。
{correctAnswer='BC'}
1
2
3
4
5
6
7
8

题库中第24题:
下列哪些叙述是错误的?(多选)
A.允许public类实现任何友好接口。
B.任何一个类都可以实现public接口。
C.如果一个类和友好接口在同一个包里,就允许它实现该接口。
D.接口变量中可以存放任何对象的引用。
{correctAnswer='AD'}
1
2
3
4
5
6
7
8

题库中第25题:
下列哪个叙述是错误的?
A 一个类最多可以实现两个接口。
B.能用public修饰接口。
C 如果一个非abstract类实现某个接口,该类必须重写接口中的全部abstract方法。
D.可以用接口名直接访问接口中的常量。
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第26题:
下列哪个叙述是错误的?
A. 接口也是Java中一种重要数据类型,用接口声明的变量称做接口变量。
B. 接口变量中可以存放实现该接口的类的实例的引用(对象的引用)。
C. 可以把一个int数据赋值给接口变量。
D. 把实现某一接口的类创建的对象的引用赋值给该接口声明的接口变量,那么该接口变量就可以调用被类实现的接口方法。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第27题:
下列哪个叙述是正确的?
A. 类和它所实现的接口必须在同一个包里。
B. 一个类声明实现一个接口,但没有重写接口中的所有方法,那么这个类必须是抽象类
C. final类不可以实现接口。
D. 允许public类实现任何友好接口。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第28题:
下列哪个叙述是错误的?
A. 接口中的方法也可以用privateprotected修饰。
B. 接口变量中可以存放实现该接口的类的实例的引用(对象的引用)。
C. 任何一个类都可以实现public接口。
D. 接口中的方法的访问权限一定都是public(允许省略public)。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第29题:
下列哪些叙述是正确的?(多选)
A. 接口中的方法也可以用privateprotected修饰。
B. 接口变量中可以存放实现该接口的类的实例的引用(对象的引用)。
C. 任何一个类都可以实现public接口。
D. 接口中的方法的访问权限一定都是public(允许省略public)。

{correctAnswer='BCD'}
1
2
3
4
5
6
7
8

题库中第30题:
下列哪个叙述是错误的?
A. 类声明class Stu extends People implements Com 意思是Stu类是People类的子类,同时实现Com接口。
B. 接口也是Java中一种重要数据类型,用接口声明的变量称做接口变量。
C. 接口中 void f();方法声明等价于public abstract void f();
D. 接口中的常量可以不指定初值,编译器会提供默认值。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第31题:
对于下列代码,哪个叙述是正确的?
interface Com {
int MAX;
public void stop();
void start();
abstract void loop();
}

A. void start();会导致编译出错。
B. public void stop(;会导致编译出错。
C abstract void loop();会导致编译出错。
D. int MAX;会导致编译出错。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第32题:
将下列(A,B,C,D)哪个代码替换下列源文件Com.java中的【代码】不会导致编译错误。
A.public int f() {
return 100+M;
}
B.int f() {
return 100;
}
C.public double f(){
return 2.6;
}
D.public abstract int f();

public interface Com {
int M = 200;
int f();
}
class ImpCom implements Com {
【代码】
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

题库中第33题:
将下列(A,B,C,D)哪个代码替换下列源文件AAA.java中的【代码】不会导致编译错误。
interface Com {
abstract void start();
void stop();
}
public class AAA implements Com {
【代码】
}

A.public void start() {
System.out.println("start");
}
B.public void start() {
System.out.println("start");
}
public void stop() {
System.out.println("stop");
}
C.public void stop() {
System.out.println("stop");
}
D.void start() {
System.out.println("start");
}
void stop() {
System.out.println("stop");
}
{correctAnswer='A'}

判断题

1
2
3
4

题库中第1题:
一个源文件中如果定义了接口,就不能再定义类。
{correctAnswer='错误'}
1
2
3
4

题库中第2题:
一个源文件中既可以定义接口,也可以定义类。
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
使用关键字interface来定义一个接口。
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
接口中只有常量,没有变量。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
接口中可只有abstract方法,不能有非abstract方法(JDK7版本)
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
接口中可以有abstract方法或default修饰的带方法体的方法(JDK8版本)。
{correctAnswer='正确'}
1
2
3
4

题库中第7题:
接口中 void f();方法声明等价于public abstract void f();即方法默认是public访问权限的abstract方法。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
接口中 int x =10等价于 public static final int x = 10,即默认是常量。
{correctAnswer='正确'}
1
2
3
4

题库中第9题:
接口里也可以定义非abstract的方法(不加default修饰)。
{correctAnswer='错误'}
1
2
3
4

题库中第10题:
一个接口可以有多个父接口:例如:interface A extends Com1,Com2
{correctAnswer='正确'}
1
2
3
4

题库中第11题:
类使用关键字implements 实现一个或多个接口。
{correctAnswer='正确'}
1
2
3
4

题库中第12题:
如果一个非abstract类实现某个接口,该类必须重写接口中的全部abstract方法。
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
可以用接口名直接访问接口中的常量。
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
不能用final修饰接口。
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
能用final修饰接口。
{correctAnswer='错误'}
1
2
3
4

题库中第16题:
能用public修饰接口。
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
能用protected修饰接口。
{correctAnswer='错误'}
1
2
3
4

题库中第18题:
接口中的方法的访问权限一定都是public(允许省略public).
{correctAnswer='正确'}
1
2
3
4

题库中第19题:
类声明class A implements Printable,Addable意思是A类实现Prinabe和Addable两个接口。
{correctAnswer='正确'}
1
2
3
4
5

题库中第20题:
类声明class Stu extends People implements Com 意思是Stu类是People类的子类,
同时实现Com接口。
{correctAnswer='正确'}
1
2
3
4

题库中第21题:
inferfce Com1 extends Com2 意思是Com1是Com2的子接口.
{correctAnswer='正确'}
1
2
3
4
5

题库中第22题:
类声明class Stu extends People implements Com 意思是Stu类是People类的子类,
父类People实现Com接口。
{correctAnswer='错误'}
1
2
3
4
5

题库中第23题:
一个类声明实现一个接口,但没有重写接口中的所有方法,那么这个类必须是抽象类,
也就是说抽象类既可以重写接口中的方法也可以直接拥有接口中的方法
{correctAnswer='正确'}
1
2
3
4

题库中第24题:
子接口将继承父接口中的全部方法和常量。
{correctAnswer='正确'}
1
2
3
4

题库中第25题:
接口也是Java中一种重要数据类型,用接口声明的变量称做接口变量。
{correctAnswer='正确'}
1
2
3
4

题库中第26题:
接口变量中可以存放实现该接口的类的实例的引用(对象的引用)。
{correctAnswer='正确'}
1
2
3
4

题库中第27题:
可以把一个int数据赋值给接口变量。
{correctAnswer='错误'}
1
2
3
4

题库中第28题:
把实现某一接口的类创建的对象的引用赋值给该接口声明的接口变量,那么该接口变量就可以调用被类实现的接口方法。
{correctAnswer='正确'}
1
2
3
4

题库中第29题:
接口中只可以有常量,不能有变量。而abstract类中既可以有常量也可以有变量。
{correctAnswer='正确'}
1
2
3
4

题库中第30题:
接口中的方法不可以用privateprotected修饰。
{correctAnswer='正确'}
1
2
3
4

题库中第31题:
接口中的方法也可以用privateprotected修饰。
{correctAnswer='错误'}
1
2
3
4

题库中第32题:
接口中的常量可以不指定初值,编译器会提供默认值。
{correctAnswer='错误'}
1
2
3
4

题库中第33题:
接口中的常量必须指定初值。
{correctAnswer='正确'}
1
2
3
4

题库中第34题:
可以用abstract修饰接口。
{correctAnswer='正确'}
1
2
3
4

题库中第35题:
可以用private或proteced修饰接口。
{correctAnswer='错误'}
1
2
3
4

题库中第36题:
一个接口可以继承多个接口。
{correctAnswer='正确'}
1
2
3
4

题库中第37题:
可以用final修饰接口中的方法。
{correctAnswer='错误'}
1
2
3
4

题库中第38题:
接口默认是public接口
{correctAnswer='错误'}
1
2
3
4

题库中第39题:
public类只能实现public接口,不能实现友好接口。
{correctAnswer='错误'}
1
2
3
4

题库中第40题:
类和它所实现的接口不一定在同一个包里。
{correctAnswer='正确'}
1
2
3
4

题库中第41题:
abstract类不能实现任何接口。
{correctAnswer='错误'}
1
2
3
4

题库中第42题:
一个类至多可实现一个接口。
{correctAnswer='错误'}
1
2
3
4

题库中第43题:
一个类不能重复实现同一个接口,例如class A implements Com,Com
{correctAnswer='正确'}
1
2
3
4

题库中第44题:
final类不能实现任何接口。
{correctAnswer='错误'}
1
2
3
4

题库中第45题:
public接口可以被任何一个类实现。一个类和友好接口在同一个包里,就允许它实现该友好接口。
{correctAnswer='正确'}
1
2
3
4

题库中第46题:
友好类和它所实现的接口必须在一个包里。
{correctAnswer='错误'}
1
2
3
4

题库中第47题:
允许public类实现任何友好接口。
{correctAnswer='错误'}
1
2
3
4

题库中第48题:
任何一个类都可以实现public接口。
{correctAnswer='正确'}
1
2
3
4

题库中第49题:
如果一个类和友好接口在同一个包里,就允许它实现该接口。
{correctAnswer='正确'}
1
2
3
4

题库中第50题:
接口变量中可以存放任何对象的引用。
{correctAnswer='错误'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
interface Com {
int M = 200;
int f(); //A
}
class People implements Com {
int f() //B
{
return 100+M; //C
}
}
class Hello implements Com {
public int f() //D
{
return 200;
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
class A {
static int m;
static void f(){
m = 20 ; //A
}
}
class B extends A {
void f() //B
{ m = 222 ; //C
}
}
class E {
public static void main(String args[]) {
A.f(); // D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
interface Com {
int M = 200;
int f(); //A
}
class People implements Com {
public int f() //B
{
return 100+M; //C
}
}
class Hello implements Com {
protected int f() //D
{
return 200;
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
interface Com {
void start(); //A
void stop(); //B
}
class AAA implements Com,Com //C
{
public void start() //D
{
System.out.println("start");
}
public void stop() {
System.out.println("stop");
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
interface Com {
protected void start(); //A
//B
}
class AAA implements Com //C
{
public void start() //D
{
System.out.println("start");
}
}

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第6题:
下列ABCD注释标注的哪行代码有错误?
abstract interface Com //A
{
void start();
char LETTER; //B
}
class AAA implements Com //C
{
public void start() //D
{
System.out.println("start");
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第7题:
下列ABCD注释标注的哪行代码有错误?
final interface Com //A
{
void start();
char LETTER = 'A'; //B
public void f(); //C
abstract int g(); //D
}

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第8题:
下列ABCD注释标注的哪行代码有错误?
class Hello {
protected void speakHello() {} //A
public abstract void cry(); //B
static int f(){ return 0 ;} //C
void start(){ } //D
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11

题库中第9题:
下列ABCD注释标注的哪行代码有错误?
abstract interface Com //A
{
void start();
char LETTER = 'A'; //B
public void f(); //C
final abstract int g(); //D
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第10题:
下列ABCD注释标注的哪行代码有错误?
interface Com
{
public static int M = 12; //A
protected char LETTER = '好'; //B
public void f(); //C
abstract int g(); //D
}

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11

题库中第11题:
下列ABCD注释标注的哪行代码有错误?
interface Com
{
public static int M = 12; //A
static char LETTER = '好'; //B
private void f(); //C
abstract int g(); //D
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第12题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
int M = 200;
int f(); //A
}
class People implements Com {
public int f() //B
{
return 100+M;
}
}
class E {
public static void main(String args[]){
People p = new People();
Com com = p; //C
com = 100; //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第13题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
int M = 200;
int f(); //A
}
class People implements Com {
public int f() //B
{
return 100+M;
}
public void g(){
System.out.println(M);
}
}
class E {
public static void main(String args[]){
People p = new People();
Com com = p; //C
int m = com.f();
com.g(); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第14题:
下列ABCD注释标注的哪行代码有错误?
abstract class A {
abstract float getFloat (); //A
void f() //B
{}
}
class B extends A {
private float m = 1.0f; //C
private float getFloat () //D
{ return m;
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第15题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
double PI = 3.14;
void showArea(double r); //A
}
class People implements Com {
public void showArea(double r) {
PI + = 0.005926; //B
System.out.println(r*r*PI);
}
public void g(){
System.out.println(Com.PI);
}
}
class E {
public static void main(String args[]){
People p = new People();
Com com = p;
com.showArea(10) ; //C
p.g(); //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第16题:
下列ABCD注释标注的哪行代码有错误?
abstract class Animal {
int m =100;
}
class Dog extends Animal{
double m;
}
public class E {
public static void main(String args[]){
Animal animal = null; //A
Dog dog = new Dog();
animal = dog; //B
dog.m = 3.14; //C
animal.m = 3.14; //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第17题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
int MAX = 100;
void cry(); //A
}
class Dog {
protected void cry() // B
{
System.out.println("wangwang");
}
}
class E {
public static void main(String args[]){
Dog dog = new Dog();
Com com = dog; //C
dog.cry(); //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第18题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
int MAX = 100;
void cry(); //A
}
class Dog implements Com {
public void cry()
{
System.out.println("wangwang");
}
protected void cry(int m)
{
System.out.println(m);
}
}
class E {
public static void main(String args[]){
Dog dog = new Dog();
Com com = dog; //B
com.cry(); //C
com.cry(100); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第19题:
下列ABCD注释标注的哪行代码有错误?
interface Com {
int MAX = 100; //A
void f();
}
abstract class Animal implements Com {
int MIN ; //B
}
class Dog extends Animal{
public void f()
{
MIN = 10; //C
MAX = 200; //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第20题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
abstract void cry(); //A
public int x = 0; //B
static int y = 0; //C
}
abstract class Cat implements Com {
abstract void cry(); //D
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第21题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
abstract void cry(); //A
public int x = 0; //B
}
abstract class Animal implements Com {
public abstract void cry();
}
class E {
public static void main(String args[]){
Animal dog = null ; // C
dog = new Animal(); // D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第22题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
abstract void cry(); //A
public int x = 0; //B
}
abstract class Animal implements Com {
}
class Dog extends Animal {
void cry() //C
{
System.out.println("wangwang");
}
}
class E {
public static void main(String args[]){
Com com = new Dog() ; //D
com.cry();
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第23题:
下列ABCD注释标注的哪行代码有错误?
public interface Com {
abstract void cry(); //A
public int x ; //B
}
abstract class Animal implements Com {
}
class Dog extends Animal {
public void cry() {
System.out.println("wangwang");
}
}
class E {
public static void main(String args[]){
Com com = new Dog() ; //C
com.cry(); //D
}
}
{correctAnswer='B'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
int MAX = 100;
int on();
}
class A implements Com{
public int on(){
return Com.MAX;
}
}
public class E {
public static void main(String args[]){
Com com = new A();
int m = com.on();
System.out.printf("%d",m);//【代码】

}
}
{correctAnswer='100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
int computer(int m,int n);
}
class A implements Com{
public int computer(int a,int b){
return a+b;
}
}
class B implements Com{
public int computer(int a,int b){
return a*b;
}
}
class People {
int a,b;
int handleDigit(Com com){
return com.computer(a,b)/2;
}
}
public class E {
public static void main(String args[]){
People p = new People ();
p.a =100;
p.b = 2;
int m = p.handleDigit(new A());
int n = p.handleDigit(new B());
System.out.printf("%d:%d",m,n);//【代码】
}
}
{correctAnswer='51:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
public abstract int computer(int a,int b);
}
class A implements Com{
public int computer(int a,int b){
return a+b;
}
}
class B implements Com{
public int computer(int a,int b){
return a*b;
}
}
class People {
Com com;
int getResult(int a,int b,int h){
return h*com.computer(a,b);
}
}
public class E {
public static void main(String args[]){
People p = new People ();
p.com = new A();
int m = p.getResult(5,6,10);
p.com = new B();
int n = p.getResult(5,6,10);
System.out.printf("%d:%d",m,n);//【代码】
}
}
{correctAnswer='110:300'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
public abstract char cry();
}
class Dog implements Com{
public char cry(){
return 'D';
}
}
class Cat implements Com{
public char cry(){
return 'C';
}
}
class People {
Com com;
char seeCry(Com com){
return com.cry();
}
}
public class E {
public static void main(String args[]){
People p = new People ();
char c1 = p.seeCry(new Dog());
char c2 = p.seeCry(new Cat());
System.out.printf("%c:%c",c1,c2);//【代码】
}
}
{correctAnswer='D:C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
int f(int x,int y);
}
class People implements Com {
public int f(int x,int y) {
return x*y;
}
int g(int a,int b) {
return a+b;
}
}
public class E {
public static void main(String args[]) {
Com com = new People();
int m = com.f(3,5);
People p = (People)com;
System.out.printf("%d:%d",m,p.g(3,5)); //【代码】
}
}

{correctAnswer='15:8'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
int add(int a,int b);
}
abstract class People {
abstract int add(int a,int b);
}
class Student extends People implements Com{
public int add(int a,int b) {
return a+b;
}
}
public class E {
public static void main(String args[]) {
Student stu = new Student();
Com com = stu;
int m = com.add(12,6);
People p = stu;
int n = p.add(12,6);
System.out.printf("%d:%d",m,n); //【代码】
}
}

{correctAnswer='18:18'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
int add(int a,int b);
public static int get(int n){ //JDK8之后允许写static方法。用接口名直接调用
return n;
}
public default int see(int n){//JDK8之后允许写default方法。
return n;
}
public default int look(int n){//JDK8之后允许写default方法。
return n;
}
}
class A implements Com{ //A类自动有default方法,允许重写.但没有接口的static方法
public int add(int a,int b) {
return a+b;
}
public int see(int n){ //重写default方法(去掉default关键字)
return n+1;
}
}
public class E {
public static void main(String args[]) {
A a = new A();
int m = a.add(12,6);
int n =Com.get(12);
int t = a.see(6);
int q = a.look(6);
System.out.printf("%d:%d:%d:%d",m,n,t,q); //【代码】
}
}


{correctAnswer='18:12:7:6'}

第7章

选择题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

题库中第1题:
编译下列E.java得到
E$1.class,
E.class,
HelloMachine.class,
SpeakHello.class
字节码文件。下列哪个叙述是正确的?
A. E$1.class是接口匿名类的字节码(编译器编译器给该匿名类的名字是E$1)。
B.E.class是接口匿名类的字节码。
C. HelloMachine.class是接口匿名类的字节码。
D. SpeakHello.class是接口匿名类的字节码.

interface SpeakHello {
void speak();
}
class HelloMachine {
public void turnOn(SpeakHello hello) {
hello.speak();
}
}
public class E {
public static void main(String args[]) {
HelloMachine machine = new HelloMachine();
machine.turnOn( new SpeakHello() { //和接口SpeakHello有关的匿名类
public void speak() {
System.out.println("hello,you are welcome!");
}
} );
}
}

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

题库中第2题:
编译下列E.java得到
E$1.class,
E.class,
HelloMachine.class,
SpeakHello.class
字节码文件。下列哪个叙述是正确的?
A. SpeakHello.class是接口匿名类的字节码。
B .E.class是接口匿名类的字节码。
C. HelloMachine.class是接口匿名类的字节码。
D. E$1.class是接口匿名类的字节码(编译器编译器给该匿名类的名字是E$1)。

abstract class SpeakHello {
abstract void speak();
}
class HelloMachine {
public void turnOn(SpeakHello hello) {
hello.speak();
}
}
public class E {
public static void main(String args[]) {
HelloMachine machine = new HelloMachine();
machine.turnOn( new SpeakHello() { //子类匿名类
public void speak() {
System.out.println("hello,you are welcome!");
}
} );
}
}


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第3题:
编译下列E.java得到的E$1.class字节码,反编译该字节码,如图7_1,jpg,下列哪个叙述是错误的?
A. 匿名类有构造方法。
B. 编译器给了匿名类一个名字:E$1
C. E$1是用户给的类名。
D. 匿名类是final类。
abstract class SpeakHello {
abstract void speak();
}
class HelloMachine {
public void turnOn(SpeakHello hello) {
hello.speak();
}
}
public class E {
public static void main(String args[]) {
HelloMachine machine = new HelloMachine();
machine.turnOn( new SpeakHello() { //子类匿名类
public void speak() {
System.out.println("hello,you are welcome!");
}
} );
}
}


{correctAnswer='C'}

null

1
2
3
4
5
6
7
8
9

题库中第4题:
哪个叙述是正确的?
A.和接口有关的匿名类可以是抽象类。
B.和类有关的匿名类还可以额外地实现某个指定的接口。
C.和类有关的匿名类一定是该类的一个非抽象子类。
D.和接口有关的匿名类的类体中可以有static成员变量。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第5题:
下列哪个叙述是错误的?
A. 内部类的外嵌类的成员变量在内部类中仍然有效。
B. 内部类中的方法也可以调用外嵌类中的方法。
C. 内部类的类体中可以声明类变量(static)变量。
D. 外嵌类的类体中可以用内部类声明对象,作为外嵌类的成员。

{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第6题:
下列哪些叙述是正确的?(多选)
A. 内部类的外嵌类的成员变量在内部类中仍然有效。
B. 内部类中的方法也可以调用外嵌类中的方法。
C. 内部类的类体中可以声明类变量(static)变量。
D. 外嵌类的类体中可以用内部类声明对象,作为外嵌类的成员。
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9

题库中第7题:
下列哪个叙述是错误的?
A. 可以用privateprotected修饰内部类。
B. 内部类仅供它的外嵌类使用,其他类不可以用某个类的内部类声明对象。
C. static内部类不能操作外嵌类中的实例成员变量。
D. 非匿名内部类不可以实现接口。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第8题:
下列哪些叙述是正确的?(多选)
A. 可以用privateprotected修饰内部类。
B. 内部类仅供它的外嵌类使用,其他类不可以用某个类的内部类声明对象。
C. static内部类不能操作外嵌类中的实例成员变量。
D. 非匿名内部类不可以实现接口。

{correctAnswer='ABC'}
1
2
3
4
5
6
7
8

题库中第9题:
下列哪个叙述是错误的?
A. 非匿名内部类也可以有(内部)子类。
B. 内部类不可以是final类。
C. 不可能用匿名类声明对象,但却可以直接用匿名类创建一个对象。
D. 匿名子类(和子类有关的匿名类)可以继承父类的方法也可以重写父类的方法。
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第10题:
下列哪些叙述是正确的?(多选)
A. 非匿名内部类也可以有(内部)子类。
B. 内部类不可以是final类。
C. 不可能用匿名类声明对象,但却可以直接用匿名类创建一个对象。
D. 匿名子类(和子类有关的匿名类)可以继承父类的方法也可以重写父类的方法。
{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9
10

题库中第11题:
下列哪个叙述是错误的?
A. 匿名子类(和子类有关的匿名类)的类体中不可以声明static成员变量和static方法。
B. 接口匿名类(和接口有关的匿名类)的类体中不可以声明static成员变量和static方法。
C. 匿名类一定是内部类。
D. Java使用throws关键字抛出一个Exception的子类的实例表示异常发生。


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第12题:
下列哪些叙述是正确的?(多选)
A. 匿名子类(和子类有关的匿名类)的类体中不可以声明static成员变量和static方法。
B. 接口匿名类(和接口有关的匿名类)的类体中不可以声明static成员变量和static方法。
C. 匿名类一定是内部类。
D. Java使用throws关键字抛出一个Exception的子类的实例表示异常发生。

{correctAnswer='ABC'}
1
2
3
4
5
6
7
8

题库中第13题:
下列哪个叙述是错误?
A. try~catch语句可以由几个catch组成,分别处理发生的相应异常。
B. 一个方法在声明时可以使用throws关键字声明要产生的若干个异常。
C. 一个方法在声明时可以使用throw关键字声明要产生的若干个异常。
D. throw的作用就是抛出异常.throw和throws是两个不同的关键字。
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第14题:
下列哪些叙述是正确的?(多选)
A. try~catch语句可以由几个catch组成,分别处理发生的相应异常。
B. 一个方法在声明时可以使用throws关键字声明要产生的若干个异常。
C. 一个方法在声明时可以使用throw关键字声明要产生的若干个异常。
D. throw的作用就是抛出异常.throw和throws是两个不同的关键字。
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9
10

题库中第15题:
下列哪个叙述是错误的?
A. 接口匿名类(和接口有关的匿名类)可以是抽象类。
B. 匿名子类(子类有关的匿名类)一定是final类。
C. 匿名子类(子类有关的匿名类)一定不是抽象类。
D. 接口匿名类(和接口有关的匿名类)一定是final类。


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第16题:
下列哪些叙述是正确的?(多选)
A. 接口匿名类(和接口有关的匿名类)可以是抽象类。
B. 匿名子类(子类有关的匿名类)一定是final类。
C. 匿名子类(子类有关的匿名类)一定不是抽象类。
D. 接口匿名类(和接口有关的匿名类)一定是final类。


{correctAnswer='BCD'}
1
2
3
4
5
6
7
8
9

题库中第17题:
下列哪个叙述是错误的?
A. 匿名类没有构造方法。
B. 匿名类只一个不带参数的构造方法(编译器会给匿名类一个名字和构造方法)。
C. 匿名类一定是final类。
D. 匿名类一定是内部类。

{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第18题:
下列哪些叙述是正确的?(多选)
A. 匿名类没有构造方法。
B. 匿名类只一个不带参数的构造方法(编译器会给匿名类一个名字和构造方法)。
C. 匿名类一定是final类。
D. 匿名类一定是内部类。
{correctAnswer='BCD'}
1
2
3
4
5
6
7
8
9

题库中第19题:
下列哪些叙述是错误的?(多选)
A. 匿名类没有构造方法。
B. 一个方法在声明时可以使用throws关键字声明要产生的若干个异常。
C. 匿名类一定是final类。
D. 匿名子类(和子类有关的匿名类)的类体中可以定义static方法。

{correctAnswer='AD'}
1
2
3
4
5
6
7
8

题库中第20题:
下列哪些叙述是正确的?(多选)
A. 匿名类没有构造方法。
B. 一个方法在声明时可以使用throws关键字声明要产生的若干个异常。
C. 匿名类一定是final类。
D. 匿名子类(和子类有关的匿名类)的类体中可以定义static方法。
{correctAnswer='BC'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第21题:
编译下列E.java得到的E$1.class字节码,反编译该字节码,如图7_1,jpg,下列哪个叙述是正确的?(多选)
A. 匿名类有构造方法。
B. 编译器给了匿名类一个名字:E$1
C. E$1是用户给的类名。
D. 匿名类是final类。
interface SpeakHello {
public abstract void speak();
}
class HelloMachine {
public void turnOn(SpeakHello hello) {
hello.speak();
}
}
public class E {
public static void main(String args[]) {
HelloMachine machine = new HelloMachine();
machine.turnOn( new SpeakHello() { //接口匿名类
public void speak() {
System.out.println("hello,you are welcome!");
}
} );
}
}


{correctAnswer='ABD'}

null

判断题

1
2
3
4

题库中第1题:
Java支持在一个类中定义一个类,这样的类称作该类的内部类。
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
内部类的外嵌类的成员变量在内部类中仍然有效。
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
内部类中的方法也可以调用外嵌类中的方法。
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
内部类的类体中不可以声明类变量和类方法。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
外嵌类的类体中可以用内部类声明对象,作为外嵌类的成员。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
可以用privateprotected修饰内部类。
{correctAnswer='正确'}
1
2
3
4

题库中第7题:
内部类仅供它的外嵌类使用,其他类不可以用某个类的内部类声明对象。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
static内部类不能操作外嵌类中的实例成员变量。
{correctAnswer='正确'}
1
2
3
4

题库中第9题:
非匿名内部类也可以实现接口。
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
非匿名内部类也可以有(内部)子类。
{correctAnswer='正确'}
1
2
3
4

题库中第11题:
内部类不可以是final类。
{correctAnswer='错误'}
1
2
3
4

题库中第12题:
不可能用匿名类声明对象,但却可以直接用匿名类创建一个对象。
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
匿名子类(和子类有关的匿名类)可以继承父类的方法也可以重写父类的方法。
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
匿名子类(和子类有关的匿名类)的类体中不可以声明static成员变量和static方法。
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
接口匿名类(和接口有关的匿名类)的类体中不可以声明static成员变量和static方法。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
匿名类一定是内部类。
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
Java使用throw关键字抛出一个Exception的子类的实例表示异常发生。
{correctAnswer='错误'}
1
2
3
4

题库中第18题:
try~catch语句可以由几个catch组成,分别处理发生的相应异常。
{correctAnswer='正确'}
1
2
3
4

题库中第19题:
一个方法在声明时可以使用throws关键字声明要产生的若干个异常。
{correctAnswer='正确'}
1
2
3
4

题库中第20题:
一个方法在声明时可以使用throw关键字声明要产生的若干个异常。。
{correctAnswer='错误'}
1
2
3
4

题库中第21题:
throw的作用就是抛出异常.throw和throws是两个不同的关键字。
{correctAnswer='正确'}
1
2
3
4

题库中第22题:
接口匿名类(和接口有关的匿名类)可以是抽象类。
{correctAnswer='错误'}
1
2
3
4

题库中第23题:
匿名子类(子类有关的匿名类)可以是抽象类。
{correctAnswer='错误'}
1
2
3
4

题库中第24题:
匿名子类(子类有关的匿名类)一定不是抽象类。
{correctAnswer='正确'}
1
2
3
4

题库中第25题:
接口匿名类(和接口有关的匿名类)一定不是抽象类。
{correctAnswer='正确'}
1
2
3
4

题库中第26题:
匿名类没有构造方法。
{correctAnswer='错误'}
1
2
3
4

题库中第27题:
匿名类只一个不带参数的构造方法(编译器会给匿名类一个名字和构造方法)。
{correctAnswer='正确'}
1
2
3
4

题库中第28题:
匿名类也有构造方法。
{correctAnswer='正确'}
1
2
3
4

题库中第29题:
匿名类一定是final类。
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
class OutClass {
int m = 1;
static float x; //A
class InnerClass {
int m =12; //B
static float n =20.89f; //C
InnerClass(){
}
void f() {
m = 100;
}
}
void cry() {
InnerClass tom = new InnerClass(); //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
class Country {
int m = 1;
float x; //A
class People {
People(){
m =12; //B
x =20.89f;//C
}
static void f() //D
{
System.out.println("Error");
}
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
abstract class A {
abstract int get();
}
class People {
int computer(A a){
return a.get();
}
}
class E {
public static void main(String args[]){
People p = new People();
int m = p.computer(new A() {
int m =100; //A
static int n =10; //B
public int get() //C
{
return 100+m; //D
}
});
System.out.println(m);
}
}

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
interface Com {
abstract int get();
}
class People {
int computer(Com com){
return com.get();
}
}
class E {
public static void main(String args[]){
People p = new People();
int m = p.computer(new Com() {
int m =100; //A
static int n =10; //B
public int get() //C
{
return 100+m; //D
}
});
System.out.println(m);
}
}

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
interface Com {
abstract int get();
}
class People {
int computer(Com com){
return com.get();
}
}
class E {
public static void main(String args[]){
People p = new People();
int m = p.computer(new Com() {
int m =100; //A
public int get() //B
{
return 100+m; //C
}
public static void f(){} //D
});
System.out.println(m);
}
}


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

题库中第6题:
下列ABCD注释标注的哪行代码有错误?
abstract class A {
abstract int get();
}
class People {
int computer(A a){
return a.get();
}
}
class E {
public static void main(String args[]){
People p = new People();
int m = p.computer(new A() {
int m =100; //A
public int get() //B
{
return 100+m; //C
}
public static void f(){} //D
});
System.out.println(m);
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第7题:
下列ABCD注释标注的哪行代码有错误?
class E {
public static void main(String args[]){
int n = 0,m = 0,t = 1000;
try{ m = Integer.parseInt("8888");
n = Integer.parseInt("ab89"); //A
}
n =100; //B
catch(NumberFormatException e) {}
try{ m = Integer.parseInt("aaaa"); //C
n = Integer.parseInt("8999"); //D
}
catch(NumberFormatException e) {}
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第8题:
下列ABCD注释标注的哪行代码有错误?
class E {
public static void main(String args[]){
int n = 0,m = 0,t = 1000;
try{ m = Integer.parseInt("8888"); //A
n = Integer.parseInt("ab89"); //B
t = Integer.parseInt("1289"); //C
}
catch(Exception e) {} //D
catch(NumberFormatException e) {}
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第9题:
下列ABCD注释标注的哪行代码有错误?
class E {
public static void main(String args[]){
int n = 0,m = 0,t = 1000;
try{ m = 8888; //A
throw new java.io.IOException("right"); //B
t = 1000; //C
}
catch(Exception e) {} //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第10题:
下列ABCD注释标注的哪行代码有错误?
class E {
public static void main(String args[]){
int n = 0,m = 0,t = 1000;
try{ m = 8888; //A
throw new NumberFormatException("right"); //B
t = 1000; //C
}
catch(Exception e) {} //D
}
}
{correctAnswer='C'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
class RedCowForm {
static class RedCow { //静态内部类RedCow是外嵌类中的一种静态数据类型
void speak() {
System.out.println("红牛");
}
}
}
class E{
public static void main(String args[]) {
RedCowForm.RedCow red = new RedCowForm.RedCow();
red.speak(); //【代码】
}
}
{correctAnswer='红牛'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
class RedCowForm {
int m =100;
RedCow cow;
RedCowForm(){
cow = new RedCow();
}
class RedCow {
int n =200;
void speak() {
System.out.printf("%d:%d",m,n);
}
}
}
class E{
public static void main(String args[]) {
RedCowForm form = new RedCowForm();
form.cow.speak(); //【代码】
}
}

{correctAnswer='100:200'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
abstract class A {
abstract int get(int a,int b);
}
public class E {
public static void main(String args[]) {
A a=new A() {
public int get(int a,int b){
return a+b;
}};
int m = a.get(2,5);
a=new A() {
public int get(int a,int b){
return a*b;
}};
int n = a.get(2,5);
System.out.printf("%d:%d",m,n);
}
}

{correctAnswer='7:10'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
abstract int get(int a,int b);
}
public class E {
public static void main(String args[]) {
Com com=new Com() {
public int get(int a,int b){
return a+b;
}};
int m = com.get(2,5);
com=new Com() {
public int get(int a,int b){
return a*b;
}};
int n = com.get(2,5);
System.out.printf("%d:%d",m,n);
}
}

{correctAnswer='7:10'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
interface Com {
abstract int get(int a,int b);
}
class People {
int getResult(Com com,int a,int b){
return com.get(a,b);
}
}
public class E {
public static void main(String args[]) {
People p = new People();
Com com=new Com() {
public int get(int a,int b){
return a+b;
}};
int m = p.getResult(com,2,5);
com=new Com(){
public int get(int a,int b){
return a*b;
}};
int n = p.getResult(com,2,5);
System.out.printf("%d:%d",m,n);
}
}


{correctAnswer='7:10'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
abstract class Computer {
abstract int get(int a,int b);
}
class People {
int getResult(Computer com,int a,int b){
return com.get(a,b);
}
}
public class E {
public static void main(String args[]) {
People p = new People();
Computer com = new Computer () {
public int get(int a,int b){
return a+b;
}};
int m = p.getResult(com,2,5);
com = new Computer (){
public int get(int a,int b){
return a*b;
}};
int n = p.getResult(com,2,5);
System.out.printf("%d:%d",m,n);
}
}


{correctAnswer='7:10'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
abstract class Computer {
abstract int get(int a,int b);
}
class People {
int a,b;
int getResult(Computer com){
return com.get(a,b);
}
}
public class E {
public static void main(String args[]) {
People p = new People();
p.a = 2;
p.b = 5;
int m = p.getResult(new Computer (){
public int get(int a,int b){
return a+b;
}});
int n = p.getResult(new Computer (){
public int get(int a,int b){
return a*b;
}});
System.out.printf("%d:%d",m,n);
}
}



{correctAnswer='7:10'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第8题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.IOException;
public class E {
public static void main(String args[]){
int m =10;
try { methodA();
m = 100;
}
catch(IOException e){
m = 1000;
}
finally {
m = 99;
}
System.out.println(m);
}
public static void methodA() throws IOException{
throw new IOException();
}
}
{correctAnswer='99'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第9题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.IOException;
public class E {
public static void main(String args[]){
int m =10;
try { methodA();
m = 100;
}
catch(IOException e){
m = 1000;
}
System.out.println(m);
}
public static void methodA() throws IOException{
throw new IOException();
}
}
{correctAnswer='1000'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

题库中第10题:
给出下列【代码】注释标注的代码的输出结果。
class ScoreException extends Exception {
int m;
ScoreException(int m){
this.m = m;
}
int getMess(){
return m;
}
}
class Teacher {
public int giveScore(int score) throws ScoreException {
if(score > 100|| score< 0)
throw new ScoreException(score);
return score;
}
}
public class E {
public static void main(String args[]){
Teacher t = new Teacher();
int m = 0,n = 0;
try { m = t.giveScore(199);
m = t.giveScore(69);
}
catch(ScoreException e){
n = e.getMess();
}
System.out.printf("%d:%d",m,n);
}
}
{correctAnswer='0:199'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

题库中第11题:
给出下列【代码】注释标注的代码的输出结果。
class ScoreException extends Exception {
int m;
ScoreException(int m){
this.m = m;
}
int getMess(){
return m;
}
}
class Teacher {
public int giveScore(int score) throws ScoreException {
if(score > 100|| score< 0)
throw new ScoreException(score);
return score;
}
}
public class E {
public static void main(String args[]){
Teacher t = new Teacher();
int m = 0,n = 0;
try { m = t.giveScore(100);
m = t.giveScore(101);
}
catch(ScoreException e){
n = e.getMess();
}
System.out.printf("%d:%d",m,n);
}
}
{correctAnswer='100:101'}

第8章

选择题

1
2
3
4
5
6
7
8
9

题库中第1题:

1.下列哪个叙述是正确的?
A. String 类是final 类,不可以有子类。
B. String 类在java.util包中。
C. "abc"=="abc"的值是false .
D. "abc".equals("Abc")的值是true
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第2题:
下列哪些叙述是错误的?(多选)
1.下列哪个叙述是正确的?
A. String 类是final 类,不可以有子类。
B. String 类在java.util包中。
C. "abc"=="abc"的值是false .
D. "abc".equals("Abc")的值是true
{correctAnswer='BCD'}
1
2
3
4
5
6
7
8

题库中第3题:
下列哪个是正确的?
A. int m =Float.parseFloat("567");
B. int m =Short.parseShort("567");
C. byte m =Integer.parseInt("2");
D. float m =Float.parseDouble("2.9");
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第4题:
哪些是错误的?(多选)
A. int m =Float.parseFloat("567");
B. int m =Short.parseShort("567");
C. byte m =Integer.parseInt("2");
D. float m =Float.parseDouble("2.9");

{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第5题:
对于如下代码,下列哪个叙述是正确的?
A. 程序编译出现错误。
B. 程序标注的【代码】的输出结果是bird。
C. 程序标注的【代码】的输出结果是fly。
D. 程序标注的【代码】的输出结果是null
public class E{
public static void main(String[] args){
String strOne="bird";
String strTwo=strOne;
strOne="fly";
System.out.println(strTwo);
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第6题:
对于如下代码,下列哪个叙述是正确的?
A. 程序编译出现错误。
B. 程序标注的【代码】的输出结果是hello。
C. 程序标注的【代码】的输出结果是你好。
D. 程序标注的【代码】的输出结果是null
public class E {
public static void main(String args[]){
String strOne = new String("你好");
String strTwo = strOne;
strOne = new String("hello");
System.out.println(strTwo);
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第7题:
对于如下代码,下列哪个叙述是正确的?
A. 程序出现编译错误。
B.无编译错误,在命令行执行程序:“java E I love this game”,程序输出this
C.无编译错误,在命令行执行程序:“java E let us go”,程序无运行异常。
D.无编译错误,在命令行执行程序:“java E 0 1 2 3 4 5 6 7 8 9”程序输出3
public class E {
public static void main (String args[]) {
String s1 = args[1];
String s2 = args[2];
String s3 = args[3];
System.out.println(s3);
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第8题:
对于如下代码,下列哪个叙述是正确的?
A. 程序出现编译错误。
B.无编译错误,在命令行执行程序:“java E I love this game”,程序输出game。
C.无编译错误,在命令行执行程序:“java E go on”,运行异常:ArrayIndexOutOfBoundsException: 2
D.无编译错误,在命令行执行程序:“java E you are ok”程序输出you。
public class E {
public static void main (String args[]) {
String s0 = args[0];
String s1 = args[1];
String s2 = args[2];
System.out.println(s2);
}
}

{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第9题:
下列哪个叙述是错误的?
A. "9dog".matches("\\ddog")的值是true
B."12hello567".replaceAll("[123456789]+","@")返回的字符串是@hello@。
C. new Date(1000)对象含有的时间是公元后1000小时的时间
D. "\\hello\n"是正确的字符串常量。
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第10题:
下列哪些叙述是正确的?(多选)
A. "9dog".matches("\\ddog")的值是true
B."12hello567".replaceAll("[123456789]+","@")返回的字符串是@hello@。
C. new Date(1000)对象含有的时间是公元后1000小时的时间
D. "\\hello\n"是正确的字符串常量。
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9
10

题库中第11题:
下列哪个叙述是错误的?
A. "\hello"是正确的字符串常量。
B. "\tea"是正确的字符串常量。
C. "\'hello"是正确的字符串常量。
D. "\natural"是正确的字符串常量。


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第12题:
下列哪些叙述是正确的?(多选)
A. "\hello"是正确的字符串常量。
B. "\tea"是正确的字符串常量。
C. "\'hello"是正确的字符串常量。
D. "\natural"是正确的字符串常量。


{correctAnswer='BCD'}
1
2
3
4
5
6
7
8

题库中第13题:
下列哪个叙述是错误?
A. 表达式"Hello".equals("hello")的值时true
B. 表达式"java".equals("java")的值是true
C. 表达式"Bird".compareTo("Bird fly")的值是负数。
D. 表达式"I love you".contains("you")的值是true
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第14题:
下列哪些叙述是正确的?(多选)
A. "default966".matches("[^bc]+[789]{1}[6]{2}")的值是true
B. 表达式"RedBird".lastIndexOf("Bird")的值是4
C. 表达式"RedBird".indexOf("Bird")的值是3
D. 表达式"RedBird".indexOf("Cat")的值是-1
{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9
10

题库中第15题:
下列哪个叙述是错误的?
A. "default966".matches("[^bc]+[789]{1}[6]{2}")的值是true
B. 表达式"RedBird".lastIndexOf("Bird")的值是4
C. 表达式"RedBird".indexOf("Bird")的值是3
D. 表达式"RedBird".indexOf("Cat")的值是-1


{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10

题库中第16题:
下列哪些叙述是正确的?(多选)
A. Integer.parseInt("12.9");会触发NumberFormatException异常。
B. 表达式"bird".contentEquals("bird")的值是true
C. 表达式"Bird" == "bird"的值是false
D. 表达式"Bird".equals("bird")的值是true


{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9

题库中第17题:
下列哪个叙述是错误的?
A. Integer.parseInt("12.9");会触发NumberFormatException异常。
B. 表达式"bird".contentEquals("bird")的值是true
C. 表达式"Bird" == "bird"的值是false
D. new String("bird") == "bird"的值是true

{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第18题:
下列哪些叙述是正确的?(多选)
A. 表达式"D:/java/book".lastIndexOf("/")的值是8
B. 表达式"3.14".matches("[0-9]+[.]{1}[0-9]+")的值是true
C. 表达式"220301200210250286".startsWith("2203")的值是true
D. 表达式"220301200210250286".endsWith("286")的值是true
{correctAnswer='BCD'}
1
2
3
4
5
6
7
8
9

题库中第19题:
下列哪个叙述是错误的?
A. 表达式"D:/java/book".lastIndexOf("/")的值是8
B. 表达式"3.14".matches("[0-9]+[.]{1}[0-9]+")的值是true
C. 表达式"220301200210250286".startsWith("2203")的值是true
D. 表达式"220301200210250286".endsWith("286")的值是true

{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第20题:
下列哪些叙述是正确的?(多选)
A. String对象的字符序列是不可修改的。
B. StringBuffer对象的字符序列是可修改的。
C. Random对象的nextInt(int n)方法随机返回[0,n]之间的一个整数。
D. 表达式"\t\nABC".length()的值是5
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9
10

题库中第21题:
下列哪些叙述是错误的?(多选)
A. 表达式"hello*?".matches("[a-zA-Z|0-9|_]+")的值是true
B. 表达式java88_hello_99".matches("[a-zA-Z|0-9|_]+")的值是true.
C. 表达式"abcdef你好".matches("[^0-9^.]+")的值是true.
D. 表达式"hello".matches("[^0-9^.]+")的值是false.


{correctAnswer='AD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第22题:
对于如下代码,下列哪个叙述是正确的?
A. 程序编译出现错误。
B. 程序标注的【代码】的输出结果是bird。
C. 程序标注的【代码】的输出结果是fly。
D. 程序标注的【代码】的输出结果是null
public class E {
public static void main (String[]args) {
String str = new String ("bird");
modify(str);
System.out.println(str); //【代码】
}
public static void modify (String s) {
s = s + "fly";
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第23题:
对于如下代码,下列哪个叙述是正确的?
A. 程序编译出现错误。
B. 程序标注的【代码】的输出结果是:hello。
C. 程序标注的【代码】的输出结果是:你好。
D. 程序标注的【代码】的输出结果是null
public class E {
public static void main (String[]args) {
String str = new String ("你好");
modify(str);
System.out.println(str); //【代码】
}
public static void modify (String s) {
s = new String("hello");
}
}
{correctAnswer='C'}

判断题

1
2
3
4

题库中第1题:
"\hello"是正确的字符串常量。
{correctAnswer='错误'}
1
2
3
4

题库中第2题:
"\\hello"是正确的字符串常量。
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
"\nhello"是正确的字符串常量。
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
"\natural"是正确的字符串常量。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
表达式"Hello".equals("hello")的值时true
{correctAnswer='错误'}
1
2
3
4

题库中第6题:
表达式"java".equals("java")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第7题:
表达式"Bird".compareTo("Bird fly")的值是负数。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
表达式"I love this game".contains("love")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第9题:
表达式"RedBird".indexOf("Bird")的值是4
{correctAnswer='错误'}
1
2
3
4

题库中第10题:
表达式"RedBird".indexOf("Bird")的值是3
{correctAnswer='正确'}
1
2
3
4

题库中第11题:
表达式"RedBird".indexOf("Cat")的值是-1
{correctAnswer='正确'}
1
2
3
4

题库中第12题:
Integer.parseInt("12.9");会触发NumberFormatException异常。
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
表达式"bird".contentEquals("bird")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
表达式"Bird".contentEquals("bird")的值是false
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
表达式"Bird".equalsIgnoreCase("bird")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
表达式"D:/java/book/E.java".lastIndexOf("/")的值是12
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
表达式"89762.34".matches("[0-9.]+")的值是true
{correctAnswer='错误'}
1
2
3
4

题库中第18题:
表达式"89762.34".startsWith("89")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第19题:
表达式"89762.34".endsWith("34")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第20题:
StringTokenizer对象的nextToken()方法返回一个String对象。
{correctAnswer='正确'}
1
2
3
4

题库中第21题:
StringTokenizer对象的countTokens()方法返回一个int型数据。
{correctAnswer='正确'}
1
2
3
4

题库中第22题:
String对象的字符序列是不可修改的。
{correctAnswer='正确'}
1
2
3
4

题库中第23题:
StringBuffer对象的字符序列是可修改的。
{correctAnswer='正确'}
1
2
3
4

题库中第24题:
Random对象的nextInt(int n)方法随机返回[0,n)之间的一个整数。
{correctAnswer='正确'}
1
2
3
4

题库中第25题:
表达式"\t\nABC".length()的值是5
{correctAnswer='正确'}
1
2
3
4

题库中第26题:
表达式 new String("abc")== "abc"的值是true
{correctAnswer='错误'}
1
2
3
4

题库中第27题:
表达式 new String("abc")== "abc"的值是false
{correctAnswer='正确'}
1
2
3
4

题库中第28题:
表达式new String("abc").contentEquals ("abc")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第29题:
表达式new String("abc").equals ("abc")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第30题:
表达式"abc" == "abc")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第31题:
表达式new String("abc") == new String("abc")的值是true
{correctAnswer='错误'}
1
2
3
4

题库中第32题:
表达式new String("abc") == new String("abc")的值是false
{correctAnswer='正确'}
1
2
3
4

题库中第33题:
表达式 ",,..\",\'...,,".matches("\\p{Punct}+")的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第34题:
表达式"hello*?".matches("[a-zA-Z|0-9|_]+")的值是false
{correctAnswer='正确'}
1
2
3
4

题库中第35题:
表达式java88_hello_99".matches("[a-zA-Z|0-9|_]+")的值是true.
{correctAnswer='正确'}
1
2
3
4

题库中第36题:
表达式"abcdef你好".matches("[^0-9^.]+")的值是true.
{correctAnswer='正确'}
1
2
3
4

题库中第37题:
表达式"23.abc".matches("[^0-9^.]+")的值是false.
{correctAnswer='正确'}
1
2
3
4

题库中第38题:
表达式"3.1415926".matches("[0-9]+[.]{1}[0-9]+")的值是true.
{correctAnswer='正确'}
1
2
3
4

题库中第39题:
表达式"3..1415926".matches("[0-9]+[.]{1}[0-9]+")的值是false.
{correctAnswer='正确'}
1
2
3
4

题库中第40题:
表达式"java".compareTo("java")的值是0
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String str1 = new String(""); //A
int [] a = {97,98,99};
String str2 = new String (a); //B
char [] c = {'a','b','c'};
String str3 = new String (c); //C
String str4 = new String(); //D
System.out.println(str4.equals(""));
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String str = new String("ABCABC");
int index = str.indexof("BC"); //A
index = str.lastIndexOf("BC"); //B
int m = str.length(); //C
boolean boo= str.startsWith("Java"); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String str = new String("ABCABC");
int index = str.indexOf("BC"); //A
index = str.lastIndexOf("BC"); //B
int m = str.length(); //C
boolean boo= str.startWith("Java"); //D
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String str = new String("ABCABC");
int index = str.indexOf("BC"); //A
index = str.lastIndexOf("BC"); //B
int m = "java".compareto("java"); //C
boolean boo= str.endsWith("Java"); //D
}
}

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String str = new String("ABCABC");
char c = str.charAt(2); //A
byte [] b = str.getBytes(); //B
String s = str.subString(0,3); //C
boolean boo= str.contains("Java"); //D
}
}


{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第6题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String str = new String("ABCABC");
boolean bn = str.equal(""); //A
byte [] b = str.getBytes(); //B
String s = str.substring(0,3); //C
boolean boo= str.contains("Java"); //D
}
}

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第7题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String str = new String("ABCABC");
int m = str.equals(""); //A
byte [] b = str.getBytes(); //B
String s = str.substring(1); //C
char [] c = str.toCharArray(); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第8题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String s = new String("ABCABC");
boolean m = s.equals(""); //A
s = s.replaceAll("[ABC]+","**"); //B
s = s.substring(1); //C
int n = s.length ; //D
System.out.println(s);
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第9题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String s = null;
s = String("ok"); //A
String str = "123"; //B
str = str.toLowerCase(); //C
str = "abcd".toUpperCase();//D
System.out.println(str);
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第10题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main (String[]args) {
String s = null;
s = new String("ok"); //A
String str = 123; //B
str = str.toLowerCase(); //C
str = "abcd".toUpperCase();//D
System.out.println(str);
}
}
{correctAnswer='B'}

读程题

1
2
3
4
5
6
7
8
9
10
11

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
String hello = "你好";
String testOne = "你"+"好";
System.out.println(hello == testOne); //【代码】
}
}
{correctAnswer='true'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
String hello = "你好";
String you = "你";
String hi = "好";
String str = you+hi;
System.out.println("你好" == str); //【代码】
}
}
{correctAnswer='false'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
String s1,s2;
s1 = new String("天道酬勤");
s2 = new String("天道酬勤");
boolean b1 = s1 == s2;
boolean b2 = s1.equals(s2);
System.out.printf("%b:%b",b1,b2); //【代码】
}
}

{correctAnswer='false:true'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
String s1 = "we are students";
String s2 = new String("we are students");
boolean b1 = s1 == s2;
boolean b2 = s1.equals(s2);
System.out.printf("%b:%b",b1,b2); //【代码】
}
}
{correctAnswer='false:true'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
String s1 = "勇者无敌";
String s2 = "勇者无敌";
boolean b1 = s1 == s2;
boolean b2 = s1.equals(s2);
System.out.printf("%b:%b",b1,b2); //【代码】
}
}


{correctAnswer='true:true'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
String str = new String ("苹果");
modify(str);
System.out.println(str); //【代码】
}
public static void modify (String s) {
s = s + "好吃";
}
}

{correctAnswer='苹果'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
String str = new String ("yes");
modify(str);
System.out.println(str); //【代码】
}
public static void modify (String s) {
s = new String("hello");
}
}

{correctAnswer='yes'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第8题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
String s = "ABCDEF";
int index = s.indexOf("C");
String str1 = s.substring(index);
String str2 = s.substring(index,index+2);
System.out.printf("%s:%s",str1,str2);
}
}
{correctAnswer='CDEF:CD'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第9题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
char [] a;
String s="ABCDEF";
a = new char[3];
s.getChars(1,4,a,0);
System.out.printf("%c%c%c",a[0],a[1],a[2]);
}
}
{correctAnswer='BCD'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第10题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
byte a [] = "Java你好".getBytes();
int m = a.length;
String s=new String(a,4,2);
System.out.printf("%d:%s",m,s);
}
}
{correctAnswer='8:你'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第11题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
int m = 0;
String regex = "[a-zA-Z|0-9|_]+";
String s ="zheng_hello678";
if(s.matches(regex)) {
m = 100;
}
else {
m = 20;
}
System.out.printf("%d",m); //【代码】
}
}
{correctAnswer='100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第12题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
int m = 0;
String regex = "[0-9]+[.]\\d+";
String s ="003.1415926";
if(s.matches(regex)) {
m = 100;
}
else {
m = 20;
}
System.out.printf("%d",m); //【代码】
}
}
{correctAnswer='100'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第13题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
String regex = "[^0-9]+";
String s ="java8,你好9";
s = s.replaceAll(regex,"1");
System.out.printf("%s",s); //【代码】
}
}

{correctAnswer='1819'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第14题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
int m = 0;
String regex = "[\\p{Punct}\\p{Blank}]+";
String [] s ="we are student,I am tehcher(hello)".split(regex);
m = s.length;
System.out.printf("%d:%s",m,s[m-1]); //【代码】
}
}

{correctAnswer='7:hello'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第15题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
int m = 0;
String regex = "[\\p{Punct}\\p{Blank}]+";
String [] s =",,,(()we are student".split(regex);
m = s.length;
System.out.printf("%d:%s",m,s[1]); //【代码】
}
}

{correctAnswer='4:we'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第16题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main (String[]args) {
int m = 0;
String regex = "\\djava\\w{1,}" ;
String str1 = "88javaookk";
String str2 = "9javaHello";
if(str1.matches(regex)) {
m++;
}
if(str2.matches(regex)) {
m++ ;
}
System.out.printf("%d",m);
}
}

{correctAnswer='1'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第17题:
给出下列【代码】注释标注的代码的输出结果。
class MyString {
public String getString(String s) {
StringBuffer str = new StringBuffer();
for(int i=0;i<s.length();i++) {
if(i%2==0) {
char c = s.charAt(i);
str.append(c);
}
}
return new String(str);
}
}
public class E {
public static void main(String args[ ]) {
String s = "ABCD";
MyString ms = new MyString();
System.out.println(ms.getString(s)); //【代码】
}
}


{correctAnswer='AC'}
1
2
3
4
5
6
7
8
9
10
11
12

题库中第18题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[ ]) {
byte d[]="abc我们喜欢篮球".getBytes();
String s=new String(d,0,7);
System.out.println(s); //【代码】
}
}

{correctAnswer='abc我们'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第19题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.StringTokenizer;
public class E {
public static void main(String args[ ]) {
String s ="we are students(hello)";
StringTokenizer fenxi = new StringTokenizer(s," ()");
int m = fenxi.countTokens();
s = fenxi.nextToken();
s = fenxi.nextToken();
int n = fenxi.countTokens();
System.out.printf("%d:%d:%s",m,n,s); //【代码】
}
}

{correctAnswer='4:2:are'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第20题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
String cost = "一班30人,二班32人,三班20人";
Scanner scanner = new Scanner(cost);
scanner.useDelimiter("[^0-9]+");
int sum = 0;
while(scanner.hasNext()){
try{ int peopleNumber = scanner.nextInt();
sum = sum+peopleNumber;
}
catch(InputMismatchException exp){
String t = scanner.next();
}
}
System.out.println(sum); //【代码】
}
}

{correctAnswer='82'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第21题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
try{
Class cs = Class.forName("java.lang.StringBuffer");
StringBuffer str = (StringBuffer)cs.newInstance();
str.append("avaj");
str.setCharAt(3 ,'J');
str.reverse();
System.out.println(str);
}
catch(Exception e){}
}
}

{correctAnswer='Java'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第22题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
String s ="987.8065";
StringTokenizer fenxi = new StringTokenizer(s,".");
int m = Integer.parseInt(fenxi.nextToken());
int n = Integer.parseInt(fenxi.nextToken());
System.out.printf("%d:%d",m,n); //【代码】
}
}

{correctAnswer='987:8065'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第23题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
String str = "现在时间是20:58:18";
str = str.replaceAll("[^0-9:]+","");
StringTokenizer fenxi = new StringTokenizer(str,":");
int h = Integer.parseInt(fenxi.nextToken());
int m = Integer.parseInt(fenxi.nextToken());
int s = Integer.parseInt(fenxi.nextToken());
System.out.printf("%d:%d:%d",h,m,s); //【代码】
}
}

{correctAnswer='20:58:18'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第24题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.regex.*;
public class E {
public static void main(String args[ ]) {
String s = "市话12.8元,长途:8.2元,短信10.9";
String regex = "[0-9]+[.][0-9]+";
Pattern p =Pattern.compile(regex);
Matcher m =p.matcher(s);
double sum =0;
while(m.find()) {
String item = m.group();
sum = sum+Double.parseDouble(item);
}
int n = (int)sum;
System.out.printf("%d",n);//【代码】
}
}

{correctAnswer='31'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第25题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.regex.*;
public class E {
public static void main(String args[ ]) {
String s = "we are students(we are from Beijing)";
String regex = "[a-zA-Z]+";
Pattern p =Pattern.compile(regex);
Matcher m =p.matcher(s);
int count =0;
String item ="";
while(m.find()) {
item = m.group();
count ++;
}
System.out.printf("%d:%s",count,item);//【代码】
}
}
{correctAnswer='7:Beijing'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第26题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.regex.*;
public class E {
public static void main(String args[ ]) {
String s = "10月1日至11月6日禁止通行";
String regex = "[0-9]+[月日]";
Pattern p =Pattern.compile(regex);
Matcher m =p.matcher(s);
int count =0;
String item ="";
while(m.find()) {
item = m.group();
count ++;
}
System.out.printf("%d:%s",count,item);//【代码】
}
}
{correctAnswer='4:6日'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第27题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.regex.*;
public class E {
public static void main(String args[ ]) {
String s = "登陆www.tup.com.cn,输入耿祥义可查询全部作者教材,欢迎您登陆";
String regex = "登陆";
Pattern p =Pattern.compile(regex);
Matcher m =p.matcher(s);
s = m.replaceAll("登录");
regex = "登录";
p =Pattern.compile(regex);
m =p.matcher(s);
int count =0;
String item ="";
while(m.find()) {
item = m.group();
count ++;
}
System.out.printf("%d:%s",count,item);
}
}
{correctAnswer='2:登录'}

第9章

选择题

1
2
3
4
5
6
7
8

题库中第1题:
以下哪个布局是JPanel容器的默认布局?
A. GridLayout
B. BorderLayout
C. CardLayout
D. FlowLayout
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第2题:
假设容器con的布局是BorderLayout,下列哪个将组建com添加到了con的北面。
A. con.add(com,BorderLayout.NORTH)。
B. con.add(com,BorderLayout.SOUTH)。
C. con.add(com,BorderLayout.EAST)。
D. con.add(com,BorderLayout.WEST)。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第3题:
假设容器con的布局是BorderLayout,下列哪个将组建com添加到了con的中心。
A. con.add(com,BorderLayout.NORTH)。
B. con.add(com)。
C. con.add(com,BorderLayout.EAST)。
D. con.add(com,BorderLayout.WEST)。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第4题:
为了给JButton按钮b注册ActionEvent事件的监视器listen,下列哪个是正确的?
A. b.addActionListener(listen);
B. b.addItemListener(listen);
C. b.addKeyListener(listen);
D. b.addWindowListener(listen);

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第5题:
为了给JButton按钮b注册MouseEvent事件的监视器listen,下列哪个是正确的?
A. b.addActionListener(listen);
B. b.addItemListener(listen);
C. b.addMouseListener(listen);
D. b.addWindowListener(listen);

{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第6题:
为了给JMenuItem菜单项b注册ActionEvent事件的监视器listen,下列哪个是正确的?
A. b.addWindowListener(listen);
B. b.addItemListener(listen);
C. b.addMouseListener(listen);
D. b.addActionListener(listen);
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第7题:
为了给JcheckBox复选框b注册ItemEvent事件的监视器listen,下列哪个是正确的?
A. b.addWindowListener(listen);
B. b.addItemListener(listen);
C. b.addMouseListener(listen);
D. b.addActionListener(listen);
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第8题:
为了给JTextField文本框b注册FocusEvent事件的监视器listen,下列哪个是正确的?
A. b.addWindowListener(listen);
B. b.addItemListener(listen);
C. b.addFocusListener(listen);
D. b.addActionListener(listen);

{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第9题:
监视器listen为了监视JTextField文本框触发的ActionEvent事件,下列哪个是正确的?
A. 创建监视器listen的类需要实现ActionListener接口。
B. 创建监视器listen的类需要实现ItemListener接口。
C. 创建监视器listen的类需要实现DocumentListener接口。
D. 创建监视器listen的类需要实现KeyListener接口。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第10题:
监视器listen为了监视JPanel容器触发的MouseEvent事件,下列哪个是正确的?
A. 创建监视器listen的类需要实现ActionListener接口。
B. 创建监视器listen的类需要实现ItemListener接口。
C. 创建监视器listen的类需要实现DocumentListener接口。
D. 创建监视器listen的类可以是MouseAdapater类的子类。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10

题库中第11题:
监视器listen为了监视JFrame窗口触发的WindowEvent事件,下列哪个是正确的?
A. 创建监视器listen的类需要实现ActionListener接口。
B. 创建监视器listen的类需要实现ItemListener接口。
C. 创建监视器listen的类需要实现DocumentListener接口。
D. 创建监视器listen的类可以是WindowAdapater类的子类。


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第12题:
监视器listen为了监视JCheckBox复选框触发的ItemEvent事件,下列哪个是正确的?
A. 创建监视器listen的类需要实现ActionListener接口。
B. 创建监视器listen的类需要实现ItemListener接口。
C. 创建监视器listen的类需要实现DocumentListener接口。
D. 创建监视器listen的类可以是MouseAdapater类的子类。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10

题库中第13题:
哪个叙述是错误的?
A. JButton在javax.swing包中。
B. ActionEvent在java.awt包中。
C. ActionListener在java.awt.event包中。
D. Font类在java.awt包中。


{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第14题:
哪个叙述是错误的?
A.javax.swing包中JComponent类是java.awt包中Container类的子类。
B.java.awt包中Container类是java.awt包中Component类的子类。
C.JFrame创建的窗口默认是可见的。
D.Java提供的JFrame类的实例就是一个底层容器,即通常所称的窗口。
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第15题:
哪个叙述是错误的?
A. JFrame窗口可以调用setLocation(int x,int y)设置自己的在显示屏上的位置。
B. 容器也可以添加JFrame的实例到该容器中。
C. JTextField文本框允许用户在文本框中输入单行文本。
D. JTextField可以触发ActionEvent事件。
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第16题:
哪些叙述是正确的?(多选)
A. JFrame窗口可以调用setLocation(int x,int y)设置自己的在显示屏上的位置。
B. 容器也可以添加JFrame的实例到该容器中。
C. JTextField文本框允许用户在文本框中输入单行文本。
D. JTextField可以触发ActionEvent事件。
{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9

题库中第17题:
下列哪些叙述是正确的?(多选)
A. WindowListener接口中只有一个方法。
B. 一个应用程序中最多只能有一个窗口。
C. JFrame创建的窗口默认是不可见的。
D. 窗口(JFrame)可以调用setSize(int int h)方法设置窗口的大小。

{correctAnswer='CD'}
1
2
3
4
5
6
7
8
9

题库中第18题:
下列哪些叙述是错误的?(多选)
A. KeyListener接口中只有一个方法。
B. 一个应用程序中最多只能有一个窗口。
C. JFrame创建的窗口默认是不可见的。
D. 窗口(JFrame)可以调用setSize(int int h)方法设置窗口的大小。

{correctAnswer='AB'}
1
2
3
4
5
6
7
8

题库中第19题:
下列哪些叙述是正确的?(多选)
A.JCheckBox复选框可以使用使用addItemLister(ItemListener l)方法将没有实现ItemListener接口的类的实例注册为自己的监视器。
B.对于有监视器的JCheckBox复选框,如果复选框的状态发生变化,就触发ItemEvent事件。"
C.监视KeyEvent事件的监视器也可以是KeyAdapater类的子类的实例。
D.JButton按钮也可以触发ItemEvent事件。
{correctAnswer='BC'}
1
2
3
4
5
6
7
8
9

题库中第20题:
下列哪个叙述是错误的?(多选)
A.JCheckBox复选框可以使用使用addItemLister(ItemListener l)方法将没有实现ItemListener接口的类的实例注册为自己的监视器。
B.对于有监视器的JCheckBox复选框,如果复选框的状态发生变化,就触发ItemEvent事件。"
C.监视KeyEvent事件的监视器也可以是KeyAdapater类的子类的实例。
D.JButton按钮也可以触发ItemEvent事件。

{correctAnswer='AD'}
1
2
3
4
5
6
7
8

题库中第21题:
下列哪些叙述是正确的?(多选)
A.使用FlowLayout布局的容器最多可以添加5个组件。
B.使用BorderLayout布局的容器被划分成5个区域。
C.JPanel的默认布局是FlowLayout布局。
D.JDialog的默认布局是CardLayout布局。
{correctAnswer='BC'}
1
2
3
4
5
6
7
8

题库中第22题:
下列哪些叙述是错误的?(多选)
A.使用FlowLayout布局的容器最多可以添加5个组件。
B.使用BorderLayout布局的容器被划分成5个区域。
C.JPanel的默认布局是FlowLayout布局。
D.JDialog的默认布局是CardLayout布局。
{correctAnswer='AD'}
1
2
3
4
5
6
7
8

题库中第23题:
下列哪些叙述是正确的?(多选)
A.JCheckBox选择框提供两种状态,一种是选中,另一种是未选中。
B.JTextArea上不能触发MouseEvent事件。
C.CheckBox选择框可以触发ItemEvent事件。
D.JTextArea文本区的Document对象可以触发DocumentEvent事件。
{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9

题库中第24题:
下列哪个叙述是错误的?
A.JCheckBox选择框提供两种状态,一种是选中,另一种是未选中。
B.JTextArea上不能触发MouseEvent事件。
C.CheckBox选择框可以触发ItemEvent事件。
D.JTextArea文本区的Document对象可以触发DocumentEvent事件。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第25题:
下列哪些叙述是正确的?(多选)
A.使用GridLayout布局的容器中的单元格大小相同。
B.一个容器可以调用setLayout(LayoutManager mgr)方法更改自己的布局。
C.java.awt.event包中的KeyAdapter类实现了KeyListener接口。
D.KeyListener接口在java.awt包中。

{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9

题库中第26题:
下列哪个叙述是错误的?
A.使用GridLayout布局的容器中的单元格大小相同。
B.一个容器可以调用setLayout(LayoutManager mgr)方法更改自己的布局。
C.java.awt.event包中的KeyAdapter类实现了KeyListener接口。
D.KeyListener接口在java.awt包中。。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

题库中第27题:
对于下列代码,哪个叙述是正确的?
A. 窗口Win的布局是BorderLayout布局。
B. 用户单击按钮b不会触发ActionEvent事件。
C. 用户单击按钮b后,按钮上的名字改变成ok。
D. 用户单击按钮b后,按钮上的名字仍然是yes。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Win extends JFrame {
JButton b;
public Win() {
setLayout(new FlowLayout());
b = new JButton("yes");
add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
b.setText("ok");
}
});
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

题库中第28题:
对于下列代码,哪些叙述是正确的?(多选)
A. 用户将复选框的状态从未选中状态变成选中状态时触发ActionEvent事件。。
B. 用户将复选框的状态从选中状态变成未选中状态时触发ActionEvent事件。
C. 用户将复选框的状态从未选中状态变成选中状态时,复选框的名字变成Yes。
D. 用户将复选框的状态从选中状态变成未选中状态时,复选框的名字变成No。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Win extends JFrame {
JCheckBox check;
public Win() {
setLayout(new FlowLayout());
check = new JCheckBox("你好");
add(check);
check.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
if(check.isSelected())
check.setText("Yes");
else
check.setText("No");
}
});
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}

{correctAnswer='CD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

题库中第29题:
对于下列代码,哪些叙述是正确的?(多选)
A. 用户第一次将鼠标指针移动进入文本区text内,text显示的文本是你好。
B. 用户将鼠标指针移动进入文本区text,触发了DocumentEvent事件。
C. 用户第1次将鼠标指针移动进入文本区text内,text显示的文本是1
D. 用户将鼠标指针退出文本区,第2次将鼠标指针移动进入文本区text内,text显示的文本是2
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Win extends JFrame {
JTextArea text;
int m = 0;
public Win() {
setSize(500,400);
text = new JTextArea("你好");
add(text);
text.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent e) {
m++;
text.setText(""+m);
}
});
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
{correctAnswer='CD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

题库中第30题:
对于下列代码,哪些叙述是正确的?(多选)
A. 用户文本框text输入文本3,文本框将显示文本9
B. 用户文本框text输入文本3然后按Enter回车键,文本框将显示文本9
C. 用户文本框text输入文本6然后按Enter回车键,文本框将显示文本36
D. 用户文本框text输入文本20,文本框将显示文本20
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Win extends JFrame {
JTextField text;
public Win() {
setSize(500,400);
setLayout(new FlowLayout());
text = new JTextField(8);
add(text);
text.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
int m = Integer.parseInt(text.getText());
text.setText(""+(m*m));
}
});
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
{correctAnswer='BC'}
1
2
3
4
5
6
7
8
9

题库中第31题:
监视器listen为了监视JTextField文本框触发的FocusEvent事件,下列哪个是正确的?
A. 创建监视器listen的类需要实现ActionListener接口。
B. 创建监视器listen的类需要实现ItemListener接口。
C. 创建监视器listen的类需要实现KeyListener接口。
D. 创建监视器listen的类可以是FocusAdapater类的子类。

{correctAnswer='B'}

判断题

1
2
3
4

题库中第1题:
javax.swing包中JComponent类是java.awt包中Container类的子类。
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
java.awt包中Container类是java.awt包中Component类的子类。
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
Container类提供了一个public方法:add( ),一个容器可以调用这个方法将组件添加到该容器中。
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
Java提供的JFrame类的实例就是一个底层容器,即通常所称的窗口。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
窗口默认地被系统添加到显示器屏幕上,因此不允许将一个窗口添加到另一个容器中。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
容器也可以添加JFrame的实例到该容器中。
{correctAnswer='错误'}
1
2
3
4

题库中第7题:
JTextField文本框允许用户在文本框中输入单行文本。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
JTextField文本框允许用户在文本框中输入多行文本。。
{correctAnswer='错误'}
1
2
3
4

题库中第9题:
JFrame类的对象的默认布局是BorderLayout布局。
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
JDialog类的对象的默认布局是BorderLayout布局。
{correctAnswer='正确'}
1
2
3
4

题库中第11题:
JTextField可以触发ActionEvent事件。
{correctAnswer='正确'}
1
2
3
4

题库中第12题:
MouseListener接口中只有一个方法。
{correctAnswer='错误'}
1
2
3
4

题库中第13题:
一个应用程序中最多只能有一个窗口。
{correctAnswer='错误'}
1
2
3
4

题库中第14题:
JFrame创建的窗口默认是不可见的。
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
窗口(JFrame)可以调用setTitle(String s)方法设置窗口的标题。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
JButton对象可以使用使用addActionLister(ActionListener l)方法将没有实现ActionListener接口的类的实例注册为自己的监视器。
{correctAnswer='错误'}
1
2
3
4
5

题库中第17题:
对于有监视器的JTextField文本框,如果该文本框处于活动状态(有输入焦点)时,
用户即使不输入文本,只要按回车(Enter)键也可以触发ActionEvent事件。
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
创建监视KeyEvent事件的监视器的类必须实现KeyListener接口。
{correctAnswer='正确'}
1
2
3
4

题库中第19题:
创建监视WindowEvent事件的监视器的类必须实现WindowListener接口。
{correctAnswer='正确'}
1
2
3
4

题库中第20题:
使用FlowLayout布局的容器最多可以添加5个组件。
{correctAnswer='错误'}
1
2
3
4

题库中第21题:
使用BorderLayout布局的容器被划分成5个区域。
{correctAnswer='错误'}
1
2
3
4

题库中第22题:
JPanel的默认布局是FlowLayout布局。
{correctAnswer='错误'}
1
2
3
4

题库中第23题:
JCheckBox选择框提供两种状态,一种是选中,另一种是未选中。
{correctAnswer='正确'}
1
2
3
4

题库中第24题:
JPasswordField密码框,允许用户在密码框中输入单行密码,默认回显字符是*。
{correctAnswer='正确'}
1
2
3
4

题库中第25题:
JCheckBox选择框可以触发ItemEvent事件。
{correctAnswer='正确'}
1
2
3
4

题库中第26题:
JTextArea文本区的Document对象可以触发DocumentEvent事件。
{correctAnswer='正确'}
1
2
3
4

题库中第27题:
任何组件上都可以发生MouseEvent事件。
{correctAnswer='正确'}
1
2
3
4
5

题库中第28题:
有模式的对话框只让程序响应对话框内部的事件,将堵塞其它线程的执行,
用户不能再激活对话框所在程序中的其它窗口,直到该对话框消失不可见。
{correctAnswer='正确'}
1
2
3
4
5
6
7

题库中第29题:
在Java中能触发事件的组件,都用方法:
addXXXListener(XXXListener listener)
将某个对象注册为自己的监视器,方法中的参数是一个接口,
listener可以引用任何实现了该接口的类所创建的对象,当事件源发生事件时,接口listener立刻回调被类实现的接口中的某个方法。
{correctAnswer='正确'}
1
2
3
4
5
6
7

题库中第30题:
MVC是:
 模型(model) 用于存储数据的对象。
 视图(view) 为模型提供数据显示的对象。
 控制器(controller) 处理用户的交互操作,对于用户的操作作出响应,让模型和视图进行必要的交互。
{correctAnswer='正确'}
1
2
3
4

题库中第31题:
使用GridLayout布局的容器中的单元格大小相同。
{correctAnswer='正确'}
1
2
3
4

题库中第32题:
一个容器可以调用setLayout(LayoutManager mgr)方法更改自己的布局。
{correctAnswer='正确'}
1
2
3
4

题库中第33题:
java.awt.event包中的WindowAdapter类实现了WindowListener接口。
{correctAnswer='正确'}
1
2
3
4

题库中第34题:
ActionListener接口在java.awt.event包中。
{correctAnswer='正确'}
1
2
3
4

题库中第35题:
java.awt.event包中的KeyAdapter类实现了KeyListener接口。
{correctAnswer='正确'}
1
2
3
4

题库中第36题:
java.awt.event包中的FocusAdapter类实现了FocusListener接口。
{correctAnswer='正确'}
1
2
3
4

题库中第37题:
java.awt.event包中的MouseAdapter类实现了MouseListener接口。
{correctAnswer='正确'}
1
2
3
4

题库中第38题:
能触发ActionEvent事件的组件调用addActionListener(ActionListener listen)方法为自己注册一个监视器。
{correctAnswer='正确'}
1
2
3
4

题库中第39题:
能触发ItemEvent事件的组件调用addItemListener(ItemListener listen)方法为自己注册一个监视器。
{correctAnswer='正确'}
1
2
3
4

题库中第40题:
创建监视ActionEvent事件的监视器的类必须实现KeyListener接口。
{correctAnswer='错误'}
1
2
3
4

题库中第41题:
创建监视FocusEvent事件的监视器的类必须实现WindowListener接口。
{correctAnswer='错误'}
1
2
3
4

题库中第42题:
创建监视ActionEvent事件的监视器的类必须实现ActionListener接口。
{correctAnswer='正确'}
1
2
3
4

题库中第43题:
创建监视ItemEvent事件的监视器的类必须实现ItemListener接口。
{correctAnswer='正确'}
1
2
3
4

题库中第44题:
创建监视KeyEvent事件的监视器的类也可以是KeyAdapater类的子类。
{correctAnswer='正确'}
1
2
3
4

题库中第45题:
创建监视WindowEvent事件的监视器的类也可以是WindowAdapter的子类。
{correctAnswer='正确'}
1
2
3
4

题库中第46题:
创建监视MouseEvent事件的监视器的类也可以是MouseAdapter的子类。
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
public class Win extends JFrame {
JTextField text;
public Win() {
setLayout(12,39); //A
setSize(500,400); //B
text = new JTextField(8);
add(text); //C
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
public class Win extends JFrame {
JTextField text;
public Win() {
setLayout(new FlowLayout()); //A
setLocation(500,400); //B
text = new TextField(8); //C
add(text);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //D
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame implements ItemListener {
JTextField text;
public Win() {
setLayout(new FlowLayout()); //A
setLocation(500,400); //B
text = new JTextField(8);
add(text);
text.addItemListener(this); //C
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //D
}
public void itemStateChanged(ItemEvent e){}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
public class Win extends JFrame implements DocumentListener {
JCheckBox check;
public Win() {
setLayout(new CardLayout()); //A
setLocation(500,400); //B
check = new JCheckBox();
add(check);
check.addDocumentListener(this); //C
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); //D
}
public void changedUpdate(DocumentEvent e) {}
public void removeUpdate(DocumentEvent e){}
public void insertUpdate(DocumentEvent e){}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
public class Win extends JFrame implements DocumentListener {
JTextArea text1,text2;
public Win() {
setLayout(new GridLayout(2,2)); //A
text1 = new JTextArea();
text2 = new JTextArea(12); //B
add(text1);
text1.getDocument().addDocumentListener(this); //C
setVisible(true);
setBounds(500,400,2,3); //D
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public void changedUpdate(DocumentEvent e) {}
public void removeUpdate(DocumentEvent e){}
public void insertUpdate(DocumentEvent e){}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第6题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
import javax.swing.*;
import java.awt.*;
public class Win extends JFrame {
public Win() {
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String args[]) {
JButton b = new JButton(); //A
Win win=new Win();
win.add(b,"java"); //B
win.setTitle("ok"); //C
win.setBounds(10,10,460,360); //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第7题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
public class Win extends JFrame {
JComponent b ;
public Win() {
b = new JButton(); //A
setLayout(new FlowLayout());
add(1,b); //B
setTitle("ok"); //C
setBounds(10,10,460,360); //D
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String args[]) {
Win win=new Win();
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第8题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
(IllegalArgumentException: adding a window to a container)
import javax.swing.*;
import java.awt.*;
public class Win extends JFrame {
JDialog dialog ;
public Win() {
dialog = new JDialog(); //A
setLayout(new FlowLayout());
add(dialog); //B
setTitle("ok"); //C
setBounds(10,10,460,360); //D
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String args[]) {
Win win=new Win();
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第9题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
(NullPointerException)
import javax.swing.*;
import java.awt.*;
public class Win extends JFrame {
JPanel panel;
public Win() {
panel.setLayout(new FlowLayout()); //A
panel = new JPanel(); //B
add(panel); //C
panel.add(new JLabel("java")); //D
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String args[]) {
Win win=new Win();
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

题库中第10题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
(NullPointerException)
import javax.swing.*;
import java.awt.*;
public class Win extends JFrame {
JPanel panel;
JButton button;
public Win() {
panel = new JPanel();
panel.setLayout(new FlowLayout()); //A
add(panel); //B
panel.add(new JLabel("java")); //C
panel.add(button); //D
button = new JButton("enter");
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String args[]) {
Win win=new Win();
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

题库中第11题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
(NullPointerException)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame implements ActionListener{
JPanel panel;
JButton button;
public Win() {
panel = new JPanel();
panel.setLayout(new FlowLayout()); //A
add(panel); //B
panel.add(new JLabel("java"));
button.addActionListener(this); //C
button = new JButton("enter");
panel.add(button); //D
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){}
public static void main(String args[]) {
Win win=new Win();
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

题库中第12题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
(NullPointerException)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame implements ActionListener{
JPanel panel;
JTextField text;
public Win() {
panel = new JPanel();
panel.setLayout(new FlowLayout()); //A
add(panel); //B
panel.add(new JLabel("java"));
text.setFont(new Font("宋体",Font.BOLD,20)); //C
text = new JTextField("ok");
text.addActionListener(this); //D
panel.add(text);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){}
public static void main(String args[]) {
Win win=new Win();
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第13题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
(IllegalArgumentException: adding a window to a container)
import javax.swing.*;
import java.awt.*;
public class Win extends JFrame {
JFrame window ;
public Win() {
window = new JFrame(); //A
setLayout(new FlowLayout());
add(window); //B
setTitle("ok"); //C
setBounds(10,10,460,360); //D
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String args[]) {
Win win=new Win();
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

题库中第14题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
(NullPointerException)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame implements ItemListener{
JPanel panel;
JCheckBox c;
public Win() {
panel = new JPanel();
panel.setLayout(new FlowLayout()); //A
c.setBackground(new Color(12,255,100)); //B
c = new JCheckBox("ok");
c.addItemListener(this); //C
add(panel); //D
panel.add(new JLabel("java"));
panel.add(c);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public void itemStateChanged(ItemEvent e){}
public static void main(String args[]) {
Win win=new Win();
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第15题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame implements ItemListener{
JCheckBox c;
public Win() {
c = new JCheckBox("ok");
c.setBackground(new Color(12,255,100)); //A
c.addItemListener(this); //B
add(c); //C
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public void itemStateChanged(ItemEvent e){
JCheckBox box = e.getSource(); //D
}
}
{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

题库中第1题:
当用户将复选框选中时(如图),给出下列【代码】注释标注的代码的输出结果。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame {
JCheckBox check;
public Win() {
setLayout(new FlowLayout());
check = new JCheckBox("good");
check.addItemListener(new Listener());
add(check);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
class Listener implements ItemListener {
public void itemStateChanged(ItemEvent e){
JCheckBox box =(JCheckBox)e.getSource();
if(box.isSelected())
System.out.println(box.getText()); //【代码】
}
}
{correctAnswer='good'}

RiTxyR.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

题库中第2题:
当用户在文本框中输入6按回车键(如图),给出下列【代码】注释标注的代码的输出结果。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame {
JTextField text;
public Win() {
setLayout(new FlowLayout());
text = new JTextField(8);
text.addActionListener(new Listener());
add(text);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
class Listener implements ActionListener {
public void actionPerformed(ActionEvent e){
JTextField text =(JTextField)e.getSource();
int m = Integer.parseInt(text.getText());
System.out.println(m*m); //【代码】
}
}
{correctAnswer='36'}

RiTjSJ.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

题库中第3题:
当用户在文本框中输入9,然后单击确定按钮(如图),给出下列【代码】注释标注的代码的输出结果。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame {
JTextField text;
JButton button;
Listener listen;
public Win() {
setLayout(new FlowLayout());
text = new JTextField(8);
button = new JButton("确定");
listen = new Listener();
listen.setView(this);
button.addActionListener(listen);
add(text);
add(button);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
class Listener implements ActionListener {
Win view;
public void actionPerformed(ActionEvent e){
int m = Integer.parseInt(view.text.getText());
System.out.println((int)Math.sqrt(m)); //【代码】
}
public void setView(Win view){
this.view = view;
}
}
{correctAnswer='3'}

RiTLYF.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

题库中第4题:
当用户在文本框中输入2,然后单击“求立方”按钮(如图),给出下列【代码】注释标注的代码的输出结果。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame {
JTextField text;
JButton buttonSquare,buttonCubic;
Listener listen;
public Win() {
setLayout(new FlowLayout());
text = new JTextField(8);
buttonSquare = new JButton("求平方");
buttonCubic = new JButton("求立方");
listen = new Listener();
listen.setView(this);
buttonSquare.addActionListener(listen);
buttonCubic .addActionListener(listen);
add(text);
add(buttonSquare);
add(buttonCubic);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
class Listener implements ActionListener {
Win view;
public void actionPerformed(ActionEvent e){
int m = Integer.parseInt(view.text.getText());
int n = 0;
if(e.getSource() == view.buttonSquare)
n =m*m;
else if (e.getSource() == view.buttonCubic)
n = m*m*m;
System.out.println(n);//【代码】
}
public void setView(Win view){
this.view = view;
}
}
{correctAnswer='8'}

RiT7wV.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

题库中第5题:
当用户在文本区中输入:abc(如图),给出下列【代码】注释标注的代码的输出结果。
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
public class Win extends JFrame {
JTextArea text;
Listener listen;
int m = 0;
public Win() {
setLayout(new FlowLayout());
text = new JTextArea(4,10);
listen = new Listener();
listen.setView(this);
text.getDocument().addDocumentListener(listen);
add(text);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
class Listener implements DocumentListener {
Win view;
public void changedUpdate(DocumentEvent e) {
view.m++;
if(view.m >= 3)
System.out.println(view.m);//【代码】
}
public void removeUpdate(DocumentEvent e) {
changedUpdate(e);
}
public void insertUpdate(DocumentEvent e) {
changedUpdate(e);
}
public void setView(Win view){
this.view = view;
}
}







{correctAnswer='3'}

RiTHoT.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

题库中第6题:
当用户将鼠标指针进入红色面板区域,然后又将鼠标指针退出红色面板区域(如图),给出下列【代码】注释标注的代码的输出结果。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame {
JPanel panel;
Listener listen;
int m = 0;
public Win() {
setLayout(new FlowLayout());
panel = new JPanel();
panel.setBackground(Color.red);
panel.setPreferredSize(new Dimension(200,160));
listen = new Listener();
listen.setView(this);
panel.addMouseListener(listen);
add(panel);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
class Listener extends MouseAdapter{
Win view;
public void mouseEntered(MouseEvent e) {
view.m++;
}
public void mouseExited(MouseEvent e) {
view.m++;
System.out.println(view.m); //【代码】
view.m = 0;
}
public void setView(Win view){
this.view = view;
}
}







{correctAnswer='2'}

RiTqFU.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

题库中第7题:
当用户执行Ctrl+A键盘操作时,给出下列【代码】注释标注的代码的输出结果。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame {
JButton button;
Listener listen;
boolean boo;
public Win() {
setLayout(new FlowLayout());
button = new JButton("ok");
listen = new Listener();
listen.setView(this);
button.addKeyListener(listen);
add(button);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
class Listener extends KeyAdapter{
Win view;
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_CONTROL)
view.boo = true;
if(e.getKeyCode() == KeyEvent.VK_A && view.boo)
System.out.println((char)e.getKeyCode()); //【代码】
}
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_CONTROL)
view.boo = false;
}
public void setView(Win view){
this.view = view;
}
}







{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

题库中第8题:
用户在前两个文本框分别输入125,然后单击相加按钮(如图), 给出下列【代码】注释标注的代码的输出结果。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame {
JTextField textN1,textN2;
JTextField showResult;
JButton buttonAdd,buttonSub;
Listener listen;
public Win() {
setLayout(new FlowLayout());
textN1 = new JTextField(8);
textN2 = new JTextField(8);
showResult = new JTextField(8);
buttonAdd = new JButton("相加");
buttonSub = new JButton("相减");
listen = new Listener();
listen.setView(this);
buttonAdd.addActionListener(listen);
buttonSub.addActionListener(listen);
add(textN1);
add(textN2);
add(showResult);
add(buttonAdd);
add(buttonSub);
setBounds(10,10,460,360);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public static void main(String args[]){
new Win();
}
}
class Listener implements ActionListener {
Win view;
public void actionPerformed(ActionEvent e){
int m = Integer.parseInt(view.textN1.getText());
int n = Integer.parseInt(view.textN2.getText());
int result = 0;
if(e.getSource() == view.buttonAdd)
result = m+n;
else if (e.getSource() == view.buttonSub)
result = m - n;
view.showResult.setText(""+result);
System.out.println(result); //【代码】
}
public void setView(Win view){
this.view = view;
}
}
{correctAnswer='17'}

RiTOW4.jpg

第10章

选择题

1
2
3
4
5
6
7
8

题库中第1题:
下列哪个叙述是正确的?
A.new File("E.java")可能发生异常。
B.BufferedRead流可以指向FileInputStream流。
C.BufferedWrite流可以指向FileWrite流。
D.RandomAccessFile流一旦指向文件,就会刷新该文件。
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第2题:
下列哪些叙述是错误的?(多选)
A.new File("E.java")可能发生异常。
B.BufferedRead流可以指向FileInputStream流。
C.BufferedWrite流可以指向FileWrite流。
D.RandomAccessFile流一旦指向文件,就会刷新该文件。

{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第3题:
为了向文件hello.txt尾加数据,下列哪些是正确创建指向hello.txt的流?(多选)
A.try { OutputStream out = new FileOutputStream ("hello.txt");
}
catch(IOException e){}

B.try { OutputStream out = new FileOutputStream ("hello.txt",true);
}
catch(IOException e){}
C.try { OutputStream out = new FileOutputStream ("hello.txt",false);
}
catch(IOException e){}
D.try { RandomAccessFile out = new RandomAccessFile("hello.txt","rw");
}
catch(IOException e){}

{correctAnswer='BD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第4题:
假设hello.txt文件的内容是:
ABCDEF
下列哪个是正确的?
A. 下列程序编译出现错误。
B. 下列程序在输出台输出字符 B。
C. 下列程序在输出台输出字符 A。
D. 下列程序在输出台输出 -1
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt");
try {
FileInputStream in = new FileInputStream(file);
int c = in.read();
c = in.read();
System.out.println((char)c);
}
catch(IOException exp){}
}
}

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第5题:
假设hello.txt文件的内容是:
ABCDEF
下列哪个是正确的?
A. 下列程序编译出现错误。
B. 下列程序在输出台输出 AB。
C. 下列程序在输出台输出字符 ABC。
D. 下列程序在输出台输出 ABCDEF。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt");
byte [] b = new byte[(int)file.length()];
try {
FileInputStream in = new FileInputStream(file);
in.read(b);
System.out.println(new String(b));
}
catch(IOException exp){}
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第6题:
假设hello.txt文件的内容是:
ABCDEF
下列哪个是正确的?
A. 下列程序编译出现错误。
B. 下列程序在输出台输出 ABCDE。
C. 下列程序在输出台输出字符 F。
D. 下列程序在输出台输出 ABCDEF。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt");
byte [] b = new byte[5];
try {
FileInputStream in = new FileInputStream(file);
int m =in.read(b,0,5);
m = in.read(b,0,5);
System.out.println(new String(b,0,m));
}
catch(IOException exp){}
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第7题:
假设hello.txt文件的内容是:
ABCDEF
下列哪个是正确的?
A. 下列程序编译出现错误。
B. 下列程序在输出台输出 ABCDE。
C. 下列程序在输出台输出字符 FBCDE。
D. 下列程序在输出台输出 ABCDEF。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt");
byte [] b = new byte[5];
try {
FileInputStream in = new FileInputStream(file);
int m =in.read(b,0,5);
m = in.read(b,0,5);
System.out.println(new String(b));
}
catch(IOException exp){}
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第8题:
假设hello.txt文件的内容是:
ABCDEF
下列哪个是正确的?
A. 下列程序编译出现错误。
B. 下列程序在输出台输出 B。
C. 下列程序在输出台输出字符 C。
D. 下列程序在输出台输出 D。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt");
try {
RandomAccessFile in = new RandomAccessFile(file,"rw");
in.seek(3);
int m = in.read();
System.out.println((char)m);
}
catch(IOException exp){}
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第9题:
假设hello.txt文件的内容是:
今天是个好日子
下列哪个是正确的?
A. 下列程序编译出现错误。
B. 下列程序在输出台输出:今天。
C. 下列程序在输出台输出:今。
D. 下列程序在输出台输出 好。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt");
try {
FileReader in = new FileReader(file);
int m =in.read();
System.out.println((char)m);
}
catch(IOException exp){}
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第10题:
假设hello.txt文件的内容是:
今天是个好日子
下列哪个是正确的?
A. 下列程序编译出现错误。
B. 下列程序在输出台输出:是。
C. 下列程序在输出台输出:今。
D. 下列程序在输出台输出 好。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt");
char [] c = new char[(int)file.length()];
try {
FileReader in = new FileReader(file);
int m =in.read(c);
System.out.println(c[2]);
}
catch(IOException exp){}
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第11题:
下列哪个是错误的?
A.File类的long length()方法返回文件的长度(单位是字节)。
B.BufferedWriter的目的地必须是字符输出流。
C.FileOutputStream输出流按字符(char)写出数据。
D.File类在java.io包中。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11

题库中第12题:
下列哪个是错误的?
A.如果磁盘不存在这样的路径:"D:\1000\a.txt,new File("D:/1000/a.txt");会触发IOExce[tion异常。
B.如果磁盘不存在这样的路径: D:/110,对于File f = new File(""D:/110"");
file.isDirectory()的值是false 。
C.如果D:/0/ 目录下不存在文件E.java,,对于File f = new File(""D:/0/"",""E.java"");
f.isFile()的值是false。
D.如果D:/0/ 目录下存有文件E.java,,对于File f = new File(""D:/0/E.java"");
f.isFile()的值是true 。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第13题:
下列哪个是错误的?
A.程序如果需要读取程序"外部"的数据,可以创建指向外部的输入流。
B.程序如果需要将程序中数据,写入到程序"外部",可以创建指向外部的输出流。
C.如果程序要读取一个文件,可以创建指向文件的FileInputStream输入流。
D.如果程序要读取一个文件,可以创建指向文件的FileOutputStream输出流。
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第14题:
下列哪个是错误的?
A.FileReader输入流按字符(char)读取文件的内容。
B.FileWriter输出流按字符(char)写出数据。
C.如果程序要读取一个文件,可以创建指向文件的FileReader输入流。
D.如果程序要读取一个文件,可以创建指向文件的FileWriter输出流。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10

题库中第15题:
下列哪个是错误的?
A 只要不关闭流,FileInputStream流每次调用read方法就从文件的头开始读取文件。
B.创建FileInputStream 对象,即文件字节输入流可能触发FileNotFoundException异常。
C.FileNotFoundException类是IOException类的子类。
D.FileInputStream流的int read(byte b[]) 方法从源中试图读取b.length个字节到字节数组b中,返回实际读取的字节数目。如果到达文件的末尾,则返回-1


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第16题:
下列哪些是正确的?(多选)
A 只要不关闭流,FileInputStream流每次调用read方法就从文件的头开始读取文件。
B.创建FileInputStream 对象,即文件字节输入流可能触发FileNotFoundException异常。
C.FileNotFoundException类是IOException类的子类。
D.FileInputStream流的int read(byte b[]) 方法从源中试图读取b.length个字节到字节数组b中,返回实际读取的字节数目。如果到达文件的末尾,则返回-1


{correctAnswer='BCD'}
1
2
3
4
5
6
7
8
9
10

题库中第17题:
下列哪个是错误的?
A.BufferedReader流的源必须是字符输入流。
B.BufferedWriter的目的地必须是字符输出流。
C.RandomAccessFile类既不是InputStream类的子类,也不是OutputStram类的子类。
D.RandomAccessFile流指向文件时,将刷新文件。


{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10

题库中第18题:
下列哪些是正确的?(多选)
A.BufferedReader流的源必须是字符输入流(FileReader)。
B.FileOutputStream流顺序地写文件,只要不关闭流,每次调用write方法就顺序地向目的地写入内容,直到流被关闭。。
C.FileInputStream流顺序地读取文件,只要不关闭流,每次调用read方法就顺序地读取源中其余的内容,直到源的末尾或流被关闭。
D.RandomAccessFile流指向文件时,将刷新文件。


{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第19题:
下列哪些out流不刷新"hello.txt"?(多选)
A.try { OutputStream out = new FileOutputStream ("hello.txt");
}
catch(IOException e){}

B.try { OutputStream out = new FileOutputStream ("hello.txt",true);
}
catch(IOException e){}
C.try { OutputStream out = new FileOutputStream ("hello.txt",false);
}
catch(IOException e){}
D.try { RandomAccessFile out = new RandomAccessFile("hello.txt","rw");
}
catch(IOException e){}

{correctAnswer='BD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第20题:
下列哪些out流刷新"hello.txt"?(多选)
A.try { OutputStream out = new FileOutputStream ("hello.txt");
}
catch(IOException e){}

B.try { OutputStream out = new FileOutputStream ("hello.txt",true);
}
catch(IOException e){}
C.try { OutputStream out = new FileOutputStream ("hello.txt",false);
}
catch(IOException e){}
D.try { RandomAccessFile out = new RandomAccessFile("hello.txt","rw");
}
catch(IOException e){}

{correctAnswer='AC'}

判断题

1
2
3
4

题库中第1题:
File类在java.io包中。
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
如果磁盘不存在这样的路径:"D:\1000\a.txt,new File("D:/1000/a.txt");会触发IOExce[tion异常。
{correctAnswer='错误'}
1
2
3
4
5

题库中第3题:
如果磁盘不存在这样的路径: D:/110,对于File f = new File("D:/110");
file.isDirectory()的值是false
{correctAnswer='正确'}
1
2
3
4
5

题库中第4题:
如果D:/0/ 目录下不存在文件E.java,,对于File f = new File("D:/0/","E.java");
f.isFile()的值是false
{correctAnswer='正确'}
1
2
3
4
5

题库中第5题:
如果D:/0/ 目录下存有文件E.java,,对于File f = new File("D:/0/E.java");
f.isFile()的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
输入流的指向称为流的源。
{correctAnswer='正确'}
1
2
3
4

题库中第7题:
输出流的指向称为流的目的地。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
程序如果需要读取程序"外部"的数据,可以创建指向外部的输入流。
{correctAnswer='正确'}
1
2
3
4

题库中第9题:
程序如果需要 将程序中数据,写入到程序"外部",可以创建指向外部的输出流。
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
如果程序要读取一个文件,可以创建指向文件的FileInputStream输入流。
{correctAnswer='正确'}
1
2
3
4

题库中第11题:
如果程序要读取一个文件,可以创建指向文件的FileOutputStream输出流。。
{correctAnswer='错误'}
1
2
3
4

题库中第12题:
FileInputStream输入流按字节(byte)读取文件的内容。
{correctAnswer='正确'}
1
2
3
4

题库中第13题:
FileOutputStream输出流按字节(byte)写出数据。
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
如果程序要读取一个文件,可以创建指向文件的FileReader输入流。
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
如果程序要读取一个文件,可以创建指向文件的FileWriter输出流。。
{correctAnswer='错误'}
1
2
3
4

题库中第16题:
FileReader输入流按字符(char)读取文件的内容。
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
FileWriter输出流按字符(char)写出数据。
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
创建FileInputStream 对象,即文件字节输入流可能触发FileNotFoundException异常。
{correctAnswer='正确'}
1
2
3
4

题库中第19题:
FileNotFoundException类是IOException类的子类。
{correctAnswer='正确'}
1
2
3
4

题库中第20题:
FileInputStream流的int read(byte b[]) 方法从源中试图读取b.length个字节到字节数组b中,返回实际读取的字节数目。如果到达文件的末尾,则返回-1
{correctAnswer='正确'}
1
2
3
4

题库中第21题:
FileInputStream流顺序地读取文件,只要不关闭流,每次调用read方法就顺序地读取源中其余的内容,直到源的末尾或流被关闭。
{correctAnswer='正确'}
1
2
3
4

题库中第22题:
FileOutputStream流顺序地写文件,只要不关闭流,每次调用write方法就顺序地向目的地写入内容,直到流被关闭。
{correctAnswer='正确'}
1
2
3
4

题库中第23题:
BufferedReader流的源必须是字符输入流。
{correctAnswer='正确'}
1
2
3
4

题库中第24题:
BufferedWriter的目的地必须是字符输出流。
{correctAnswer='正确'}
1
2
3
4

题库中第25题:
RandomAccessFile类既不是InputStream类的子类,也不是OutputStram类的子类。
{correctAnswer='正确'}
1
2
3
4

题库中第26题:
RandomAccessFile流指向文件时,不刷新文件。
{correctAnswer='正确'}
1
2
3
4

题库中第27题:
File类的long length()返回文件的长度(单位是字节)。
{correctAnswer='正确'}
1
2
3
4

题库中第28题:
RandomAccessFile类的seek(long a)方法,将读写位置定位于距离文件开头a个字节处。
{correctAnswer='正确'}
1
2
3
4

题库中第29题:
RandomAccessFile类的seek(long a)方法,将读写位置定位于文件的第a个字节处。
{correctAnswer='错误'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt"); //A
long m = file.length(); //B
FileReader in = new FileReader(file); //C
try{
FileWriter out = new FileWriter(file); //D
}
catch(IOException exp){}
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt"); //A
long m = file.length(); //B
try{
FileReader in = new FileReader(file);
BufferedReader bufferRead =new BufferedReader(file);//C
FileWriter out = new FileWriter(file); //D
}
catch(IOException exp){}
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt"); //A
int m = file.length(); //B
try{
FileReader in = new FileReader(file);
BufferedReader bufferRead =new BufferedReader(in);//C
FileWriter out = new FileWriter(file); //D
}
catch(IOException exp){}
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt"); //A
int m = file.isFile(); //B
try{
FileReader in = new FileReader(file);
BufferedReader bufferRead =new BufferedReader(in);//C
String s = bufferRead.readLine(); //D
}
catch(IOException exp){}
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第5题:
下列ABCD注释标注的哪行代码有错误?
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt"); //A
boolean m = file.isFile(); //B
try{
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream objectOut = new ObjectOutputStream(file);//C
objectOut.writeObject(new Integer(100)); //D
objectOut.close();
}
catch(IOException exp){}
}
}
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第6题:
下列ABCD注释标注的哪行代码没有编译错误,但触发运行异常?
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt"); //A
try{
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);//B
objectOut.writeObject(new Integer(100)); //C
objectOut.close();
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
Integer number = objectIn.readObject(); //D
System.out.println(number.intValue());
}
catch(Exception exp){}
}
}
{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.txt");
try{
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
objectOut.writeObject(new Integer(100));
objectOut.close();
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
Integer number = (Integer)objectIn.readObject();
System.out.println(number.intValue()); //【代码】
}
catch(Exception exp){}
}
}
{correctAnswer='100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第2题:
假设hello.txt的大小为4个字节(byte),给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]) {
File f = new File("hello.txt");
try{ RandomAccessFile in = new RandomAccessFile(f,"rw");
long m = f.length();
FileOutputStream out = new FileOutputStream(f);
long n = f.length();
System.out.printf("%d:%d",m,n) ; //【代码】
}
catch(IOException e) {
System.out.println("File read Error"+e);
}
}
}
{correctAnswer='4:0'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第3题:
假设a.txt的大小为4个字节(byte),给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]) {
File f = new File("a.txt");
try{ RandomAccessFile in = new RandomAccessFile(f,"rw");
long m = f.length();
FileOutputStream out = new FileOutputStream(f,true);
long n = f.length();
System.out.printf("%d:%d",m,n) ; //【代码】
}
catch(IOException e) {
System.out.println("File read Error"+e);
}
}
}
{correctAnswer='4:4'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]){
int n=-1;
File f =new File("hello.txt");
byte [] a="abcd".getBytes();
try{ FileOutputStream out=new FileOutputStream(f);
out.write(a);
out.close();
FileInputStream in=new FileInputStream(f);
byte [] tom= new byte[100];
int m = in.read(tom);
String s=new String(tom,0,m);
System.out.printf("%d:%s",m,s); //【代码】
}
catch(IOException e) {}
}
}
{correctAnswer='4:abcd'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]){
int n=-1;
File f = new File("hello.txt");
char[] a ="你好hello".toCharArray();
try{ FileWriter out=new FileWriter(f);
out.write(a);
out.close();
FileReader in=new FileReader(f);
char [] tom= new char[4];
int m = in.read(tom);
String s=new String(tom,0,m);
System.out.printf("%d:%s",m,s); //【代码】
}
catch(IOException e) {}
}
}
{correctAnswer='4:你好he'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]) {
RandomAccessFile inAndOut = null;
int m = 12;
long n = 99;
try{ inAndOut = new RandomAccessFile("tom.dat","rw");
inAndOut.writeInt(m);
inAndOut.writeLong(n);
inAndOut.seek(4);
long t1 = inAndOut.readLong();
inAndOut.seek(0);
long t2 = inAndOut.readInt();
System.out.printf("%d:%d",t1,t2);
inAndOut.close();
}
catch(IOException e){}
}
}
{correctAnswer='99:12'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
import java.util.*;
public class E {
public static void main(String args[]){
int sum= 0;
File f =new File("hello.txt");
byte [] b = "苹果 12元,鸭梨18元".getBytes();
try{
FileOutputStream out = new FileOutputStream(f);
out.write(b);
out.close();
Scanner sc = new Scanner(f);
sc.useDelimiter("[^0123456789]+");
while(sc.hasNextInt()){
int n = sc.nextInt();
sum += n;
}
System.out.println(sum);

}
catch(IOException e) {}
}
}
{correctAnswer='30'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

题库中第8题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
import javax.swing.JButton;
public class E {
public static void main(String args[]){
File file = new File("hello.data");
JButton button = new JButton("yes");
try{
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
objectOut.writeObject(button);
objectOut.close();
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
JButton b = (JButton)objectIn.readObject();
b.setText("ok");
System.out.printf("%s:%s",button.getText(),b.getText()); //【代码】
}
catch(Exception exp){}
}
}
{correctAnswer='yes:ok'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第9题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.text");
byte [] b = "ABCDEF".getBytes();
try{
FileOutputStream out = new FileOutputStream(file);
out.write(b);
FileInputStream in = new FileInputStream(file);
int c = in.read();
c = in.read();
System.out.println((char)c);//【代码】
}
catch(Exception exp){}
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第10题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.text");
byte [] b = "ABCDEF".getBytes();
try{
FileOutputStream out = new FileOutputStream(file);
out.write(b);
FileInputStream in = new FileInputStream(file);
int m = in.read(b);
String s = new String(b);
System.out.printf("%d:%s",m,s);//【代码】
}
catch(Exception exp){}
}
}
{correctAnswer='6:ABCDEF'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第11题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.text");
byte [] b = "abcdef".getBytes();
try{
FileOutputStream out = new FileOutputStream(file);
out.write(b);
FileInputStream in = new FileInputStream(file);
byte [] a = new byte[5];
int m =in.read(a,0,5);
String s1 = new String(a);
m = in.read(a,0,5);
String s2 = new String(a);
System.out.printf("%s:%s",s1,s2); //【代码】
}
catch(Exception exp){}
}
}
{correctAnswer='abcde:fbcde'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第12题:
给出下列【代码】注释标注的代码的输出结果。
import java.io.*;
public class E {
public static void main(String args[]){
File file = new File("hello.text");
char [] tom = new char[3];
try{
FileWriter out = new FileWriter(file);
out.write("大家好");
out.close();
FileReader in = new FileReader(file);
int m =in.read(tom);
System.out.println(new String(tom));//【代码】
}
catch(Exception exp){}
}
}
{correctAnswer='大家好'}

第11章

选择题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第1题:
下列哪个是加载JDBC-MySQL数据库驱动(连接器)
A. try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
B. try{ Class.forName("oracle.jdbc.driver.oracleDriver");
}
catch(Exception e){}
C. try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception e){}
D. try{ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
}
catch(Exception e){}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第2题:
下列哪个是加载JDBC-SQLServer数据库驱动(连接器)
A. try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
B. try{ Class.forName("oracle.jdbc.driver.oracleDriver");
}
catch(Exception e){}
C. try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception e){}
D. try{ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
}
catch(Exception e){}

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第3题:
下列哪个是加载JDBC-Oracle数据库驱动(连接器)
A. try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
B. try{ Class.forName("oracle.jdbc.driver.oracleDriver");
}
catch(Exception e){}
C. try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception e){}
D. try{ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
}
catch(Exception e){}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第4题:
下列哪个是加载JDBC-Derby数据库驱动(连接器)
A. try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
B. try{ Class.forName("oracle.jdbc.driver.oracleDriver");
}
catch(Exception e){}
C. try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception e){}
D. try{ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
}
catch(Exception e){}

{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第5题:
下列哪个是正确的?(多选)
A.在MySQL安装目录的bin子目录下键入mysqld或mysqld -nt 启动MySQL数据库服务器。
B.在MySQL安装目录的bin子目录下键入mysql 启动MySQL数据库服务器。
C.MySQL服务器默认占用的端口是3306
D.MySQL服务器的默认用户是root,密码为空(没有密码)。
{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9

题库中第6题:

下列哪个是错误的?
A.在MySQL安装目录的bin子目录下键入mysqld或mysqld -nt 启动MySQL数据库服务器。
B.在MySQL安装目录的bin子目录下键入mysql 启动MySQL数据库服务器。
C.MySQL服务器默认占用的端口是3306
D.MySQL服务器的默认用户是root,密码为空(没有密码)。
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11

题库中第7题:

下列哪个是错误的?
A.ResultSet对象和数据库连接对象(Connection对象)实现了紧密的绑定,一旦连接对象被关闭,ResultSet对象中的数据立刻消失。
B.ResultSet对象一次只能看到一个数据行,使用next()方法移到下一个数据行,
next()方法最初的查询位置,即游标位置,位于第一行的前面。
C.连接对象调用prepareStatement(String sql)方法对参数sql指定的SQL语句进行预编译处理,
并返回一个Statement对象。
D.Navicat for MySQL是一款MySQL客户端管理工具 。
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第8题:

下列哪些是正确的?(多选)
A.SQL语句:select * from mess where height>1.6 and height<=1.8
是查询mess表中字段(列)height值在1.61.8之间的记录(记录的各个列值都要)。
B. SQL语句 select * from mess where name like '%林%'
是查询mess表中字段(列)name值等于“林”的记录(记录的各个列值都要)。
C.SQL语句 update mess set height =1.77 where name='张三'
是将mess表中name字段(列)值是张三的记录(行)的height的值更新为1.77
D. SQL语句 insert into mess values
('R1008','将林','2010-12-20',1.66),('R1008','秦仁','2010-12-20',1.66)
是向表mess里添加了两条记录(两行)。

{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第9题:
下列哪个是错误的?
A.SQL语句:select * from mess where height>1.6 and height<=1.8
是查询mess表中字段(列)height值在1.61.8之间的记录(记录的各个列值都要)。"
B. SQL语句 select * from mess where name like '%林%'
是查询mess表中字段(列)name值等于“林”的记录(记录的各个列值都要)。"
C.SQL语句 update mess set height =1.77 where name='张三'
是将mess表中name字段(列)值是张三的记录(行)的height的值更新为1.77
D. SQL语句 insert into mess values
('R1008','将林','2010-12-20',1.66),('R1008','秦仁','2010-12-20',1.66)
是向表mess里添加了两条记录(两行)。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第10题:
下列哪个是错误的?
A.程序使用PreparedStatement对象不仅减轻了数据库的负担,而且也提高了访问数据库的速度。
B.连接对象调用prepareStatement(String sql)方法对参数sql指定的SQL语句进行预编译处理,
并返回一个PreparedStatement对象。
C.结果集rs执行rs.getString(1)按字符串返回结果集当前行第1列的值。
D."jdbc:mysql://localhost:3306/students?useSSL=true"中的"mysql"是用户数据库的名字。
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10

题库中第11题:
下列哪个是错误的?
A.程序使用PreparedStatement对象会加重数据库的负担。
B.连接对象调用prepareStatement(String sql)方法对参数sql指定的SQL语句进行预编译处理,
并返回一个PreparedStatement对象。
C.结果集rs执行rs.getString(1)按字符串返回结果集当前行第1列的值。
D."jdbc:mysql://localhost:3306/students?useSSL=true"中的"students"是用户数据库的名字。

{correctAnswer='A'}

判断题

1
2
3
4

题库中第1题:
在MySQL安装目录的bin子目录下键入mysqld或mysqld -nt 启动MySQL数据库服务器。
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
在MySQL安装目录的bin子目录下键入mysql 启动MySQL数据库服务器。
{correctAnswer='错误'}
1
2
3
4

题库中第3题:
MySQL服务器默认占用的端口是3306
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
MySQL服务器的默认用户是root,密码为空(无密码)。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
Navicat for MySQL是一款MySQL客户端管理工具 。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
Class.forName("com.mysql.jdbc.Driver")是加载的JDBC-MySQL数据库驱动。。
{correctAnswer='正确'}
1
2
3
4
5

题库中第7题:
ResultSet对象和数据库连接对象(Connection对象)实现了紧密的绑定,一旦连接对象被关闭,
ResultSet对象中的数据立刻消失。
{correctAnswer='正确'}
1
2
3
4
5

题库中第8题:
ResultSet对象一次只能看到一个数据行,使用next()方法移到下一个数据行,
next()方法最初的查询位置,即游标位置,位于第一行的前面。
{correctAnswer='正确'}
1
2
3
4
5

题库中第9题:
SQL语句:select * from mess where height>1.6 and height<=1.8
是查询mess表中字段(列)height值在1.61.8之间的记录(记录的各个列值都要)。
{correctAnswer='正确'}
1
2
3
4
5

题库中第10题:
SQL语句 select * from mess where name like '%林%'
是查询mess表中字段(列)name值包含有“林”的记录(记录的各个列值都要)。
{correctAnswer='正确'}
1
2
3
4
5

题库中第11题:
SQL语句 update mess set height =1.77 where name='张三'
是将mess表中name字段(列)值是张三的记录(行)的height的值更新为1.77
{correctAnswer='正确'}
1
2
3
4
5
6

题库中第12题:
SQL语句 insert into mess values
('R1008','将林','2010-12-20',1.66),('R1008','秦仁','2010-12-20',1.66)
是向表mess里添加了两条记录(两行)。
{correctAnswer='正确'}
1
2
3
4
5

题库中第13题:
SQL语句delete from mess where number = 'R1002'
是删除了mess表中字段number值是R1002的记录。
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
事务由一组SQL语句组成,所谓事务处理是指:应用程序保证事务中的SQL语句要么全部都执行,要么一个都不执行。
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
PreparedStatement对象被习惯地称做预处理语句对象。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
程序使用PreparedStatement对象不仅减轻了数据库的负担,而且也提高了访问数据库的速度。
{correctAnswer='正确'}
1
2
3
4
5

题库中第17题:
连接对象调用prepareStatement(String sql)方法对参数sql指定的SQL语句进行预编译处理,
并返回一个PreparedStatement对象。
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
import java.sql.*;
public class E {
public static void main(String args[]) {
Connection con=null; //A
Statement sql; //B
ResultSet rs; //C
Class.forName("com.mysql.jdbc.Driver"); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
import java.sql.*;
public class E {
public static void main(String args[]) {
Connection con=null;
Statement sql;
ResultSet rs;
try{ Class.forName("com.mysql.jdbc.Driver"); //A
}
catch(Exception e){}
String uri = "jdbc:mysql://localhost:3306/students?useSSL=true"; //B
String user ="root";
String password ="";
try{
con = DriverManager.getConnection(uri,user,password); //C
}
catch(SQLException e){ }
sql=con.createStatement(); //D
}
}
{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

题库中第1题:
用户数据库为students,其中的表mess的结构与部分记录如图。给出下列【代码】注释标注的代码的输出结果。
import java.sql.*;
public class E {
public static void main(String args[]) {
Connection con=null;
Statement sql;
ResultSet rs;
try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
String uri = "jdbc:mysql://localhost:3306/students?useSSL=true";
String user ="root";
String password ="";
try{
con = DriverManager.getConnection(uri,user,password);
}
catch(SQLException e){ }
try {
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM mess where number = '00000'");
if(rs.next()) {
String height=rs.getString(4);
System.out.printf("%s\n",height);//【代码】
}
con.close();
}
catch(SQLException e) {}
}
}


{correctAnswer='1.63'}

RiTvl9.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

题库中第2题:
用户数据库为students,其中的表mess的结构与部分记录如图。给出下列【代码】注释标注的代码的输出结果。
import java.sql.*;
public class E {
public static void main(String args[]) {
Connection con=null;
Statement sql;
ResultSet rs;
try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
String uri = "jdbc:mysql://localhost:3306/students?useSSL=true";
String user ="root";
String password ="";
try{
con = DriverManager.getConnection(uri,user,password);
}
catch(SQLException e){ }
String str = "SELECT birthday,name FROM mess where"+
" year(birthday)=1989 and month(birthday)=9 and day(birthday)=10";
try {
sql=con.createStatement();
rs=sql.executeQuery(str);
if(rs.next()) {
String name=rs.getString(2);
System.out.printf("%s\n",name);//【代码】
}
con.close();
}
catch(SQLException e) {}
}
}


{correctAnswer='大刘伟'}

RiTvl9.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

题库中第3题:
用户数据库为students,其中的表mess的结构与部分记录如图。给出下列【代码】注释标注的代码的输出结果。
import java.sql.*;
public class E {
public static void main(String args[]) {
Connection con=null;
Statement sql;
ResultSet rs;
try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
String uri = "jdbc:mysql://localhost:3306/students?useSSL=true&characterEncoding=utf-8";
String user ="root";
String password ="";
try{
con = DriverManager.getConnection(uri,user,password);
}
catch(SQLException e){ }
String jiLu= "('T1001','安卓','2000-10-23',1.66),"+
"('T1002','安康','1989-7-22',1.76)";
String sqlStr ="insert into mess values"+jiLu;

String str = "SELECT name,height FROM mess where "+
" number = 'T1001'";
try {
sql=con.createStatement();
sql.executeUpdate(sqlStr);
rs=sql.executeQuery(str);
if(rs.next()) {
String name=rs.getString(1);
String h=rs.getString(2);
System.out.printf("%s:%s\n",name,h);//【代码】
}
con.close();
}
catch(SQLException e) {}
}
}


{correctAnswer='安卓:166'}

RiTvl9.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

题库中第4题:
用户数据库为students,其中的表mess的结构与部分记录如图。给出下列【代码】注释标注的代码的输出结果。
import java.sql.*;
public class E {
public static void main(String args[]) {
Connection con=null;
PreparedStatement sql;
ResultSet rs;
try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
String uri = "jdbc:mysql://localhost:3306/students?useSSL=true&characterEncoding=utf-8";
String user ="root";
String password ="";
try{
con = DriverManager.getConnection(uri,user,password);
}
catch(SQLException e){ }
String sqlStr ="update mess set name = ? ,height = ? where number = ? ";
String str = "SELECT name,height FROM mess where number = '00000'";
try {
sql=con.prepareStatement(sqlStr);
sql.setString(1,"耿祥义");
sql.setFloat(2,1.72F);
sql.setString(3,"00000");
sql.executeUpdate();
rs=sql.executeQuery(str);
if(rs.next()) {
String name=rs.getString(1);
String h=rs.getString(2);
System.out.printf("%s:%s\n",name,h);//【代码】
}
con.close();
}
catch(SQLException e) {System.out.println(e);}
}
}


{correctAnswer='耿祥义:1.72'}

RiTvl9.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

题库中第5题:
用户数据库为students,其中的表mess的结构与部分记录如图。给出下列【代码】注释标注的代码的输出结果。
import java.sql.*;
public class E {
public static void main(String args[]) {
Connection con=null;
PreparedStatement sql;
ResultSet rs;
try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
String uri = "jdbc:mysql://localhost:3306/students?useSSL=true&characterEncoding=utf-8";
String user ="root";
String password ="";
try{
con = DriverManager.getConnection(uri,user,password);
}
catch(SQLException e){ }
String sqlStr ="insert into mess values(?,?,?,?)";
String str = "SELECT name,height FROM mess where number = 'AABBCC'";
try {
sql=con.prepareStatement(sqlStr);
sql.setString(1,"AABBCC");
sql.setString(2,"郑州好");
sql.setString(3,"2002-12-09");
sql.setFloat(4,1.76f);
sql.executeUpdate();
rs=sql.executeQuery(str);
if(rs.next()) {
String name=rs.getString(1);
String h=rs.getString(2);
System.out.printf("%s:%s\n",name,h);//【代码】
}
con.close();
}
catch(SQLException e) {System.out.println(e);}
}
}


{correctAnswer='郑州好:1.76'}

RiTvl9.jpg

第12章

选择题

1
2
3
4
5
6
7
8

题库中第1题:
下列哪个是正确的?
A. 线程被创建,在JVM管理的线程队列立刻就有这个线程。
B. 当一个线程进入中断状态后,它被放在JVM管理的线程队列中的最前面排队等待CPU资源,以便从中断处继续运行。
C. 一个线程从死亡状态可以再回到中断状态。
D. 线程调用start()方法可以使一个线程成为可运行的,但是它不一定立即开始运行。
{correctAnswer='D'}
1
2
3
4
5
6
7

题库中第2题:
A.线程新建后,可以调用run方法进入运行状态。
B.如果两个线程需要调用同一个同步方法,那么一个线程调用该同步方法时,另一个线程必须等待。
C.线程的目标对象中的run方法可能启动多次。
D.默认情况下,所有线程的优先级都是5级。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第3题:
下列哪个叙述是正确的?
A.run()方法是Runnable接口中的方法。
B.start()方法是Runnable接口中的方法。
C.sleep()方法是Runnable接口中的方法。
D.interrupt()方法是Runnable接口中的方法。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第4题:
下列哪个叙述是正确的?
A.多线程需要多个CPU才可以。
B.多线程需要多个进程来实现。
C.一个进程可以产生多线程。
D.线程之间无法实现数据共享。
{correctAnswer='C'}
1
2
3
4
5
6
7
8

题库中第5题:
下列哪个方法可以让新建的线程进入JVM管理的线程列队中?
A.start()。
B.run()。
C.init()。
D.isAlive()。
{correctAnswer='A'}
1
2
3
4
5
6
7
8

题库中第6题:
wait()方法、notify()及notifyAll()方法在下列哪个类或接口中?
A.java.lang.Thread。
B.java.lang.Object。
C.java.lang.Runnable。
D.java.lang.System。
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第7题:
下列哪些叙述是正确的?(多选)
A.线程不是进程,但其行为很象进程,线程是比进程更小的执行单位。
B. 一个进程在其执行过程中,可以产生多个线程。
C.一个进程在其执行过程中,至多可以产生1个线程。
D. JVM加载代码,发现主类的main方法之后,就会启动一个线程,这个线程称为“主线程”(main线程),该线程负责执行main方法。
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9

题库中第8题:
哪个叙述是错误的?
A.线程不是进程,但其行为很象进程,线程是比进程更小的执行单位。
B. 一个进程在其执行过程中,可以产生多个线程。
C.一个进程在其执行过程中,至多可以产生1个线程。
D. JVM加载代码,发现主类的main方法之后,就会启动一个线程,这个线程称为“主线程”(main线程),该线程负责执行main方法。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第9题:
下列哪些叙述是正确的?(多选)
A.线程在它的一个完整的生命周期中通常要经历如下的四种状态:1.新建, 2.运行 ,3中断,4.死亡。
B.可以使用Thread类或其子类创建(新建)线程。
C.线程调用start方法将启动线程,使之从新建状态进入就绪队列排队.
一旦轮到它来享用CPU资源时,就可以脱离创建它的线程独立开始自己的生命周期了。
D.线程不调用start方法,JVM就也会把它当作一个线程来对待(JVM管理的线程队列有这个线程)。
{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9
10

题库中第10题:
哪个叙述是错误的?
A.线程在它的一个完整的生命周期中通常要经历如下的四种状态:1.新建, 2.运行 ,3中断,4.死亡。
B.可以使用Thread类或其子类创建(新建)线程。
C.线程调用start方法将启动线程,使之从新建状态进入就绪队列排队.
一旦轮到它来享用CPU资源时,就可以脱离创建它的线程独立开始自己的生命周期了。
D.线程不调用start方法,JVM就也会把它当作一个线程来对待(JVM管理的线程队列有这个线程)。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10

题库中第11题:
哪个叙述是错误的?
A.线程处于“新建”状态时(在调用start方法之前),线程调用isAlive()方法返回的值是false
B. 线程处于“新建”状态时(在调用start方法之前),线程调用isAlive()方法返回的值是true
C. currentThread()方法是Thread类中的static方法,该方法返回当前正在使用CPU资源的线程.
D. 线程调用interrupt()方法将使得处于speep方法或wait方法中断的该线程触发InterruptedException异常。


{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11

题库中第12题:
哪些叙述是正确的?(多选)
A.线程处于“新建”状态时(在调用start方法之前),线程调用isAlive()方法返回的值是false
B. 线程处于“新建”状态时(在调用start方法之前),线程调用isAlive()方法返回的值是true
C. currentThread()方法是Thread类中的static方法,该方法返回当前正在使用CPU资源的线程.
D. 线程调用interrupt()方法将触发InterruptedException异常。



{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9
10
11

题库中第13题:
哪些叙述是正确的?(多选)
A.进入运行状态的线程,调用isAlive()方法返回的值是true
B. 新建状态的线程调用isAlive()方法返回的值是false
C. currentThread()方法是Thread类中的static方法,该方法返回当前正在使用CPU资源的线程.
D. Java中的线程不可以共享数据。



{correctAnswer='ABC'}
1
2
3
4
5
6
7
8
9
10
11

题库中第14题:
哪个叙述是错误的?
A.进入运行状态的线程(run方法未结束),调用isAlive()方法返回的值是true
B. 新建状态的线程调用isAlive()方法返回的值是false
C. currentThread()方法是Thread类中的static方法,该方法返回当前正在使用CPU资源的线程.
D. Java中的线程不可以共享数据。



{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第15题:
对于下列程序,哪个叙述是正确的?
A.JVM认为这个应用程序共有两个线程。
B.JVM认为这个应用程序只有一个主线程。
C.JVM认为这个应用程序只有一个thread线程。
D.thread的优先级是10级。
public class E {
public static void main(String args[]) {
Target target =new Target();
Thread thread =new Thread(target);
thread.start();
}
}
class Target implements Runnable{
public void run(){
System.out.println("ok");
}
}


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第16题:
对于下列程序,哪个叙述是正确的?
A.JVM认为这个应用程序共有两个线程。
B.JVM认为这个应用程序只有一个主线程。
C.JVM认为thread在JVM管理的线程队列里。
D.程序有编译错误,无法运行。
public class E {
public static void main(String args[]) {
Target target =new Target();
Thread thread =new Thread(target);
target.run();
}
}
class Target implements Runnable{
public void run(){
System.out.println("ok");
}
}


{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

题库中第17题:
对于下列程序,哪些叙述是错误的?(多选)
A.JVM认为这个应用程序共有两个线程。
B.JVM认为这个应用程序只有一个主线程。
C.JVM认为thread在JVM管理的线程队列里。
D.程序有编译错误,无法运行。
public class E {
public static void main(String args[]) {
Target target =new Target();
Thread thread =new Thread(target);
target.run();
}
}
class Target implements Runnable{
public void run(){
System.out.println("ok");
}
}


{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第18题:
对于下列程序,哪些叙述是错误的?(多选)
A.JVM认为这个应用程序共有两个线程。
B.JVM认为这个应用程序只有一个主线程。
C.JVM认为dog在JVM管理的线程队列里。
D.程序有编译错误,无法运行。
public class E {
public static void main(String args[]) {
Dog dog =new Dog();
dog.run();
}
}
class Dog extends Thread{
public void run(){
System.out.println("ok");
}
}


{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第19题:
对于下列程序,哪个叙述是正确的?
A.JVM认为这个应用程序共有两个线程:主线程和dog线程。
B.JVM认为这个应用程序只有一个主线程。
C.JVM认为这个应用程序只有一个dog线程。
D.程序有编译错误,无法运行。
public class E {
public static void main(String args[]) {
Dog dog =new Dog();
dog.start();
while(true){
System.out.println("yes");
}
}
}
class Dog extends Thread{
public void run(){
while(true){
System.out.println("ok");
}
}
}


{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第20题:
对于下列程序,哪个叙述是正确的?
A.JVM认为这个应用程序共有两个线程:主线程和dog线程。
B.JVM认为dog在JVM管理的线程列队中。
C.应用程序可以编译通过,运行效果是:循环地输出ok。
D.程序有编译错误,无法运行。
public class E {
public static void main(String args[]) {
Dog dog =new Dog();
dog.run();
while(true){
System.out.println("yes");
}
}
}
class Dog extends Thread{
public void run(){
while(true){
System.out.println("ok");
}
}
}


{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第21题:
对于下列程序,哪个叙述是正确的?
A.应用程序运行效果是:循环地只输出yes。
B.程序没有编译错误,但运行时触发NullPointerException。
C.应用程序可以编译通过,运行效果是:循环地只输出ok。
D.程序有编译错误。
public class E {
public static void main(String args[]) {
Dog dog =new Dog();
dog.run();
while(true){
System.out.println("yes");
}
}
}
class Dog extends Thread{
public void run(){
while(true){
System.out.println("ok");
}
}
}


{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

题库中第22题:
对于下列程序,哪个叙述是正确的?
A.应用程序可以编译通过,运行效果是:循环地只输出ok。
B.程序没有编译错误,但运行时触发NullPointerException。
C.应用程序可以编译通过,运行效果是:循环地交替输出几个ok或几个yes。
D.程序有编译错误。
public class E {
public static void main(String args[]) {
Dog dog =new Dog();
dog.start();
while(true){
System.out.println("yes");
}
}
}
class Dog extends Thread{
public void run(){
while(true){
System.out.println("ok");
}
}
}


{correctAnswer='C'}
1
2
3
4
5
6
7
8
9
10

题库中第23题:
哪些叙述是正确的?(多选)
A.一个线程A调用synchronized方法期间,其他线程也可以能成功调用这个synchronized方法。
B. wait()、notify()和notifyAll()都是Object类中的final方法,
被所有的类继承、且不允许重写的方法。
C. 一个线程在执行同步方法时,如果执行wait()方法,使本线程进入中断,就允许其它线程使用这个同步方法。
D. 一个因执行wait方法进入中断状态的线程,需要其他线程执行notify()或notifyAll()通知它结束中断状态。

{correctAnswer='BCD'}
1
2
3
4
5
6
7
8
9
10

题库中第24题:
哪个叙述是错误的?
A.一个线程A调用synchronized方法期间,其他线程也可以能成功调用这个synchronized方法。
B. wait()、notify()和notifyAll()都是Object类中的final方法,
被所有的类继承、且不允许重写的方法。
C. 一个线程在执行同步方法时,如果执行wait()方法,使本线程进入中断,就允许其它线程使用这个同步方法。
D. 一个因执行wait方法进入中断状态的线程,需要其他线程执行notify()或notifyAll()通知它结束中断状态。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第25题:
哪个叙述是错误的?
A.一个线程A调用synchronized方法期间,执行sleep方法进入中断后,其他线程就能成功调用这个synchronized方法。
B. 线程在执行完run()方法之前,如果再次让线程执行start方法,
就会发生ILLegalThreadStateException 异常。
C. javax.swing.Timer类称为计时器线程,计时器的监视器必须是组件类的子类的实例,否则计时器无法启动。
D. 线程默认是非守护线程。当程序中的所有非守护户线程都已结束运行时,即使守护线程的run方法中还有需要执行的语句,守护线程也立刻结束运行。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10

题库中第26题:
哪些叙述是正确的?(多选)
A.一个线程调用synchronized方法期间,执行sleep方法进入中断后,其他线程就能成功调用这个synchronized方法。
B. 线程在执行完run()方法之前,如果再次让线程执行start方法,
就会发生ILLegalThreadStateException 异常。
C. javax.swing.Timer类称为计时器线程,计时器的监视器必须是组件类的子类的实例,否则计时器无法启动。
D. 线程默认是非守护线程。当程序中的所有非守护户线程都已结束运行时,即使守护线程的run方法中还有需要执行的语句,守护线程也立刻结束运行。

{correctAnswer='BCD'}

判断题

1
2
3
4

题库中第1题:
线程不是进程,但其行为很象进程,线程是比进程更小的执行单位。
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
一个进程在其执行过程中,可以产生多个线程。
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
一个进程在其执行过程中,至多可以产生1个线程。
{correctAnswer='错误'}
1
2
3
4

题库中第4题:
Java应用程序总是从主类的main方法开始执行,JVM加载代码,发现main方法之后,就会启动一个线程,这个线程称为“主线程”(main线程),该线程负责执行main方法。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
线程在它的一个完整的生命周期中通常要经历如下的四种状态:1.新建, 2.运行 ,3中断,4.死亡。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
可以使用Thread类或其子类创建(新建)线程。
{correctAnswer='正确'}
1
2
3
4
5

题库中第7题:
线程调用start方法将启动线程,使之从新建状态进入就绪队列排队.
一旦轮到它来享用CPU资源时,就可以脱离创建它的线程独立开始自己的生命周期了.
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
线程不调用start方法,JVM就不会把它当作一个线程来对待,仅仅当作一个普通的对象而已。
{correctAnswer='正确'}
1
2
3
4

题库中第9题:
线程处于“新建”状态时(在调用start方法之前),线程调用isAlive()方法返回的值是false
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
线程处于“新建”状态时(在调用start方法之前),线程调用isAlive()方法返回的值是true
{correctAnswer='错误'}
1
2
3
4

题库中第11题:
currentThread()方法是Thread类中的static方法,该方法返回当前正在使用CPU资源的线程.
{correctAnswer='正确'}
1
2
3
4

题库中第12题:
线程调用interrupt()方法将使得处于speep方法或wait方法中断的该线程触发InterruptedException异常。
{correctAnswer='正确'}
1
2
3
4
5

题库中第13题:
当一个线程调用synchronized方法时,其他线程想调用这个synchronized方法时就必须等待,
直到线程A调用完该synchronized方法。
{correctAnswer='正确'}
1
2
3
4
5

题库中第14题:
wait()、notify()和notifyAll()都是Object类中的final方法,
被所有的类继承、且不允许重写的方法。
{correctAnswer='正确'}
1
2
3
4
5

题库中第15题:
一个线程在执行同步方法时,如果执行wait()方法,使本线程进入中断,
就允许其它线程使用这个同步方法。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
一个因执行wait方法进入中断状态的线程,需要其他线程执行notify()或notifyAll()通知它结束中断状态。
{correctAnswer='正确'}
1
2
3
4
5

题库中第17题:
线程在执行完run()方法之前,如果再次让线程执行start方法,
就会发生ILLegalThreadStateException 异常。
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
javax.swing.Timer类称为计时器线程,计时器的监视器必须是组件类的子类的实例,否则计时器无法启动。
{correctAnswer='正确'}
1
2
3
4
5

题库中第19题:
线程默认是非守护线程。当程序中的所有非守护户线程都已结束运行时,
即使守护线程的run方法中还有需要执行的语句,守护线程也立刻结束运行。
{correctAnswer='正确'}
1
2
3
4

题库中第20题:
必须在synchronized方法中使用wait()方法、notify()及notifyAll()方法。
{correctAnswer='正确'}
1
2
3
4

题库中第21题:
线程的默认级别是10级。
{correctAnswer='错误'}
1
2
3
4

题库中第22题:
Java中的线程不可以共享数据。
{correctAnswer='错误'}
1
2
3
4

题库中第23题:
进入运行状态的线程,调用isAlive()方法返回的值是true
{correctAnswer='正确'}
1
2
3
4

题库中第24题:
一个线程调用synchronized方法期间,执行sleep方法进入中断后,其他线程就能成功调用这个synchronized方法。
{correctAnswer='错误'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main(String args[]) {
Dog dog =new Dog(); //A
Cat cat =new Cat(); //B
cat.start(); //C
while(true){
System.out.println("yes");
}
dog.start(); //D
}
}
class Dog extends Thread{
public void run(){
while(true){
System.out.println("dog");
}
}
}
class Cat extends Thread{
public void run(){
while(true){
System.out.println("cat");
}
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
public class E {
public static void main(String args[]) {
Target t = new Target();
Thread dog =new Thread(t); //A
Thread cat =new Thread(new Target()); //B
dog.start(); //C
while(true){
System.out.println("yes");
}
cat.start(); //D
}
}
class Target implements Runnable{
public void run(){
while(true){
System.out.println("ok");
}
}
}
{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
Target t = new Target();
Thread dog =new Thread(t);
Thread cat =new Thread(t);
dog.start();
cat.start();
while(true){
if(dog.isAlive() == false&&cat.isAlive() == false) {
break;
}
}
System.out.println(t.buffer); //【代码】
}
}
class Target implements Runnable{
StringBuffer buffer;
Target(){
buffer = new StringBuffer();
}
public void run(){
f();
}
public synchronized void f(){
for(int i = 1;i<= 3;i++){
buffer.append(i);
}
}
}

{correctAnswer='123123'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
Target t = new Target();
Thread dog =new Thread(t);
Thread cat =new Thread(t);
dog.start();
cat.start();
}
}
class Target implements Runnable{
int number = 0;
public void run(){
f();
}
public synchronized void f(){
while( number < 6 ){
try{
number = 6;
wait();
System.out.printf("%d",number); //【代码】
}
catch(InterruptedException exp){}
}
number = 10;
notify();
}
}

{correctAnswer='10'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
public class E {
public static void main(String args[]) {
Target t = new Target();
Thread dog =new Thread(t);
Thread cat =new Thread(t);
dog.start();
cat.start();
}
}
class Target implements Runnable{
String s = "abc";
public void run(){
f();
}
public synchronized void f(){
while( s.length() <= 3){
try{
s = "Java";
wait();
System.out.printf("%s",s); //【代码】
}
catch(InterruptedException exp){}
}
s = "hello";
notify();
}
}


{correctAnswer='hello'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
public class Target implements Runnable {
StringBuffer buffer=new StringBuffer();
Thread cat,dog;
Target() { cat=new Thread(this);
dog=new Thread(this);
}
public synchronized void addChar(char c) {
if(Thread.currentThread()==cat) {
while(buffer.length()==0) {
try{ wait();
}
catch(Exception e){}
}
buffer.append(c);
}
if(Thread.currentThread()==dog) {
buffer.append(c);
notifyAll();
}
}
public void run() {
if(Thread.currentThread()==cat)
addChar('A') ;
if(Thread.currentThread()==dog)
addChar('B') ;
}
public static void main(String s[]) {
Target target=new Target();
target.cat.start();
target.dog.start();
while(target.cat.isAlive()||target.dog.isAlive()){}
System.out.println(target.buffer); //【代码】
}
}
{correctAnswer='BA'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
import java.awt.*;
import java.awt.event.*;
public class Target implements Runnable {
StringBuffer buffer=new StringBuffer();
Thread cat,dog,mouse;
Target() { cat=new Thread(this);
dog=new Thread(this);
mouse=new Thread(this);
}
public synchronized void addChar(char c) {
if(Thread.currentThread()==cat) {
while(buffer.length()==0) {
try{ wait();
System.out.println("cat");
}
catch(Exception e){}
}
buffer.append(c);
notifyAll();
}
if(Thread.currentThread()==dog) {
while(buffer.length()==0||buffer.length()==1) {
try{ wait();
System.out.println("dog");
}
catch(Exception e){}
}
buffer.append(c);
}
if(Thread.currentThread()==mouse) {
buffer.append(c);
notifyAll();
}
}
public void run() {
if(Thread.currentThread()==cat)
addChar('1') ;
if(Thread.currentThread()==dog)
addChar('2') ;
if(Thread.currentThread()==mouse)
addChar('3') ;
}
public static void main(String s[]) {
Target target=new Target();
target.cat.start();
target.dog.start();
target.mouse.start();
while(target.cat.isAlive()||target.dog.isAlive()|target.mouse.isAlive()){}
System.out.println(target.buffer); //【代码】
}
}
{correctAnswer='312'}

第13章

选择题

1
2
3
4
5
6
7
8

题库中第1题:
下列哪个是错误的?
A. java.net包中的URL类的实例,即对象封装着着一个具体的资源。
B. 一个URL对象通常只包含1部分信息:协议。
C. URL类创建对象需要捕获MalformedURLException异常 。
D. URL是Uniform Resource Locator的缩写。
{correctAnswer='B'}
1
2
3
4
5
6
7
8

题库中第2题:
下列哪些是正确的?(多选)
A. java.net包中的URL类的实例,即对象封装着着一个具体的资源。
B. 一个URL对象通常只包含1部分信息:协议。
C. URL类创建对象需要捕获MalformedURLException异常 。
D. URL是Uniform Resource Locator的缩写。
{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9

题库中第3题:
下列哪个是错误的?
A. 一个URL对象通常包含最基本的三部分信息:协议、地址、资源。
B. URL类创建对象需要捕获MalformedURLException异常 。
C. 对于URL url = new URL(""http://www.google.com"");
url对象中的协议是ftp协议,包含的地址是www.google.com,包含的资源是默认的资源(主页)。
D. URL对象调用InputStream openStream() 方法可以返回一个输入流,该输入流指向URL对象所包含的资源。
{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第4题:
下列哪些是正确的?(多选)
A. 一个URL对象通常包含最基本的三部分信息:协议、地址、资源。
B. URL类创建对象需要捕获MalformedURLException异常 。
C. 对于URL url = new URL(""http://www.google.com"");
url对象中的协议是ftp协议,包含的地址是www.google.com,包含的资源是默认的资源(主页)。
D. URL对象调用InputStream openStream() 方法可以返回一个输入流,该输入流指向URL对象所包含的资源。
{correctAnswer='ABD'}
1
2
3
4
5
6
7
8
9
10
11

题库中第5题:
下列哪些叙述是正确的(多选)?
A. 端口号是一个16位的0~65535之间的整数。
B. Socket的构造方法Socket(String host,int port)创建流套接字,但不呼叫连接主机host。
C. Socket的构造方法Socket()创建一个未连接的套接字。
套接字再调用
public void connect(SocketAddress endpoint) throws IOException
请求和参数SocketAddress指定的服务器端的套接字建立连接。
D. 客户端的程序使用Socket类建立负责连接到服务器的套接字对象。
{correctAnswer='ACD'}
1
2
3
4
5
6
7
8
9
10
11

题库中第6题:
哪一个是错误的?
A. 端口号是一个16位的0~65535之间的整数。
B. Socket的构造方法Socket(String host,int port)创建流套接字,但不呼叫连接主机host。
C. Socket的构造方法Socket()创建一个未连接的套接字。
套接字再调用
public void connect(SocketAddress endpoint) throws IOException
请求和参数SocketAddress指定的服务器端的套接字建立连接。"
D. 客户端的程序使用Socket类建立负责连接到服务器的套接字对象。
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10

题库中第7题:
哪个是错误的?
A.客户端的程序使用Socket类建立负责连接到服务器的套接字对象。
B.服务器使用ServerSocket对象将客户端的套接字对象和服务器端的一个套接字对象连接起来,
从而达到连接的目的。
C.服务器端的ServerSocket对象调用方法accept()返回一个和客户的套接字相连接的套接字对象。
D.套接字是基于UDP协议的网络通信。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11

题库中第8题:
哪些是正确的(多选)?
A.客户端的程序使用Socket类建立负责连接到服务器的套接字对象。
B.服务器使用ServerSocket对象将客户端的套接字对象和服务器端的一个套接字对象连接起来,
从而达到连接的目的。
C.服务器端的ServerSocket对象调用方法accept()返回一个和客户的套接字相连接的套接字对象。
D.套接字是基于UDP协议的网络通信。


{correctAnswer='ABC'}
1
2
3
4
5
6
7
8

题库中第9题:
哪个是错误的?
A. 239.255.8.0是D类地址。
B. 61.135.169.121是A类地址。
C. 172.22.102.19是B类地址。
D. 190.124.12.17是C类地址。
{correctAnswer='D'}
1
2
3
4
5
6
7
8

题库中第10题:
哪个是错误的?
A. 192.255.8.0是D类地址。
B. 61.135.169.121是A类地址。
C. 172.22.102.19是B类地址。
D. 192.124.12.17是C类地址。
{correctAnswer='A'}

判断题

1
2
3
4

题库中第1题:
URL是Uniform Resource Locator的缩写。
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
java.net包中的URL类的实例,即对象封装着着一个具体的资源。
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
一个URL对象通常包含最基本的三部分信息:协议、地址、资源。
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
URL类创建对象需要捕获MalformedURLException异常 。
{correctAnswer='正确'}
1
2
3
4
5

题库中第5题:
对于URL url = new URL("http://www.google.com");
url对象中的协议是http协议,包含的地址是www.google.com,包含的资源是默认的资源(主页)。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
URL对象调用InputStream openStream() 方法可以返回一个输入流,该输入流指向URL对象所包含的资源。。
{correctAnswer='正确'}
1
2
3
4

题库中第7题:
端口号是一个16位的0~65535之间的整数。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
Socket的构造方法Socket(String host,int port)创建流套接字并“呼叫”连接主机host。
{correctAnswer='正确'}
1
2
3
4
5
6
7

题库中第9题:
Socket的构造方法Socket()创建一个未连接的套接字。
套接字再调用
public void connect(SocketAddress endpoint) throws IOException
请求和参数SocketAddress指定的服务器端的套接字建立连接。
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
客户端的程序使用Socket类建立负责连接到服务器的套接字对象。
{correctAnswer='正确'}
1
2
3
4
5

题库中第11题:
服务器使用ServerSocket对象将客户端的套接字对象和服务器端的一个套接字对象连接起来,
从而达到连接的目的。
{correctAnswer='正确'}
1
2
3
4

题库中第12题:
服务器端的ServerSocket对象调用方法accept()返回一个和客户的套接字相连接的套接字对象。
{correctAnswer='正确'}
1
2
3
4
5

题库中第13题:
套接字是基于TCP协议的网络通信,即客户端程序和服务器端程序是有连接的,
双方的信息是通过程序中的输入、输出流来交互的。
{correctAnswer='正确'}
1
2
3
4

题库中第14题:
要广播或接收广播的主机都必须加入到同一个D类地址。
{correctAnswer='正确'}
1
2
3
4

题库中第15题:
239.255.8.0是D类地址。
{correctAnswer='正确'}
1
2
3
4

题库中第16题:
61.135.169.121是A类地址。
{correctAnswer='正确'}
1
2
3
4

题库中第17题:
172.22.102.19是B类地址
{correctAnswer='正确'}
1
2
3
4

题库中第18题:
192.124.12.17是C类地址
{correctAnswer='正确'}
1
2
3
4

题库中第19题:
200.255.8.0是D类地址。
{correctAnswer='错误'}
1
2
3
4

题库中第20题:
161.135.169.121是A类地址。
{correctAnswer='错误'}
1
2
3
4

题库中第21题:
192.22.102.19是B类地址
{correctAnswer='错误'}
1
2
3
4

题库中第22题:
162.124.12.17是C类地址
{correctAnswer='错误'}
1
2
3
4

题库中第23题:
ServerSocket对象调用accept方法返回一个Socket对象。
{correctAnswer='正确'}
1
2
3
4

题库中第24题:
ServerSocket对象调用accept方法返回一个URL对象。
{correctAnswer='错误'}
1
2
3
4

题库中第25题:
ServerSocket对象调用accept方法返回一个InetAddress对象。
{correctAnswer='错误'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
import java.net.*;
import java.io.*;
public class E {
public static void main(String args[]) {
URL urlOne,urlTwo = null;
try {
urlOne = new URL("http://news.baidu.com/"); //A
urlTwo = new URL("http://www.baidu.com/"); //B
InputStream in = urlOne.openStream(); //C
OutputStream out = urlTwo.openStream(); //D

}
catch(Exception exp){}
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
import java.net.*;
import java.io.*;
public class E {
public static void main(String args[]) {
try{
InetAddress address_1 =
InetAddress.getByName("www.tup.com.cn"); //A
System.out.println(address_1.getHostName()); //B
System.out.println(address_1.getHostAddress()); //C
String name = InetAddress.getLocalHost(); //D
}
catch(UnknownHostException e) {}
}
}
{correctAnswer='D'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

题库中第1题:
网络套接字连接的客户端和服务器的代码分别如下:
给出下列客户端【代码】注释标注的代码的输出结果。
//客户端代码:
import java.io.*;
import java.net.*;
public class Client {
public static void main(String args[]) {
String mess ="hello";
Socket clientSocket;
DataInputStream in=null;
DataOutputStream out=null;
try{ clientSocket = new Socket("127.0.0.1",2019);
in = new DataInputStream(clientSocket.getInputStream());
out = new DataOutputStream(clientSocket.getOutputStream());
out.writeUTF(mess);
String s=in.readUTF();
System.out.println(s); //【代码】
}
catch(Exception e) {}
}
}
//服务器端代码:
import java.io.*;
import java.net.*;
public class Server {
public static void main(String args[]) {
String answer = "你好";
ServerSocket serverForClient = null;
Socket socketOnServer = null;
DataOutputStream out = null;
DataInputStream in = null;
try { serverForClient = new ServerSocket(2019);
}
catch(IOException e1) {}
try{
socketOnServer = serverForClient.accept();
out = new DataOutputStream(socketOnServer.getOutputStream());
in = new DataInputStream(socketOnServer.getInputStream());
String s = in.readUTF();
System.out.println(s);
out.writeUTF(answer);
}
catch(Exception e) {}
}
}

{correctAnswer='你好'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

题库中第2题:
网络套接字连接的客户端和服务器的代码分别如下:
给出下列服务器【代码】注释标注的代码的输出结果。
//客户端代码:
import java.io.*;
import java.net.*;
public class Client {
public static void main(String args[]) {
String mess ="hello";
Socket clientSocket;
DataInputStream in=null;
DataOutputStream out=null;
try{ clientSocket = new Socket("127.0.0.1",2019);
in = new DataInputStream(clientSocket.getInputStream());
out = new DataOutputStream(clientSocket.getOutputStream());
out.writeUTF(mess);
String s=in.readUTF();
System.out.println(s);
}
catch(Exception e) {}
}
}
//服务器端代码:
import java.io.*;
import java.net.*;
public class Server {
public static void main(String args[]) {
String answer = "你好";
ServerSocket serverForClient = null;
Socket socketOnServer = null;
DataOutputStream out = null;
DataInputStream in = null;
try { serverForClient = new ServerSocket(2019);
}
catch(IOException e1) {}
try{
socketOnServer = serverForClient.accept();
out = new DataOutputStream(socketOnServer.getOutputStream());
in = new DataInputStream(socketOnServer.getInputStream());
String s = in.readUTF();
System.out.println(s); //【代码】
out.writeUTF(answer);
}
catch(Exception e) {}
}
}

{correctAnswer='hello'}

第14章

选择题

1
2
3
4
5
6
7
8
9

题库中第1题:
下列哪个类负责创建“直线”对象?
A. Line2D.Double。
B. Rectangle2D.Double。
C. RoundRectangle2D.Double。
D. Ellipse2D.Double。

{correctAnswer='A'}
1
2
3
4
5
6
7
8
9

题库中第2题:
下列哪个类负责创建“圆角矩形”对象?
A. Line2D.Double。
B. Rectangle2D.Double。
C. RoundRectangle2D.Double。
D. Ellipse2D.Double。

{correctAnswer='C'}
1
2
3
4
5
6
7
8
9

题库中第3题:
下列哪个类负责创建“矩形”对象?
A. Line2D.Double。
B. Rectangle2D.Double。
C. RoundRectangle2D.Double。
D. Ellipse2D.Double。

{correctAnswer='B'}
1
2
3
4
5
6
7
8
9

题库中第4题:
下列哪个类负责创建“椭圆”对象?
A. Line2D.Double。
B. Rectangle2D.Double。
C. RoundRectangle2D.Double。
D. Ellipse2D.Double。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第5题:
下列哪个类负责创建“圆弧”对象?
A. Line2D.Double。
B. Rectangle2D.Double。
C. RoundRectangle2D.Double。
D. Arc2D.Double。

{correctAnswer='D'}

判断题

1
2
3
4

题库中第1题:
public void paint(Graphics g)方法是java.awt.Component类提供的方法。
{correctAnswer='正确'}
1
2
3
4

题库中第2题:
Graphicd2D是Graphics的一个子类。
{correctAnswer='正确'}
1
2
3
4

题库中第3题:
Line2D是java.awt.geom包中的的类,
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
java.awt.geom包中的的Rectangle2D的静态内部类Double可以创建Rectangle2D对象。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
new Rectangle2D.Double(0,0,100,50)创建了一个左上角坐标是(0,0),宽和高分别是10050的Rectangle2D矩形对象。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
new Ellipse2D.Double (10,5,100,50 )创建了一个左上角坐标是(10,5),宽和高分别是10050的Ellipse2D椭圆对象
{correctAnswer='正确'}
1
2
3
4

题库中第7题:
Graphics2D对象调用drawString(String s, int x, int y)方法从参数x、y指定的坐标位置处,从左向右绘制参数s指定的字符串s。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
AudioClip和Applet类属于java.applet包中的类。
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
class MyCanvas extends JPanel {
public void paint(Graphics g) {
Graphics2D g_2d=(Graphics2D)g; //A
Arc2D arc=new Arc2D.Double(0,0,100,100,-90,-180,Arc2D.PIE); //B
g_2d.fill(arc); //C
g.draw(arc); //D
}
}

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
class E extends JPanel {
public void paint(Graphics g) {
Graphics2D g_2d=(Graphics2D)g;
Line2D line =new Line2D.Double(12,23,100,9); //A
Ellipse2D tuxing= new Ellipse2D.Double(100,200); //B
g_2d.fill(tuxing); //C
g_2d.draw(tuxing); //D
}
}
{correctAnswer='B'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
class E extends JPanel {
public void paint(Graphics g) {
Graphics2D g_2d=(Graphics2D)g;
Line2D line =new Line2D.Double(12,23); //A
Ellipse2D tuxing= new Ellipse2D.Double(1,220,9); //B
g_2d.fill(tuxing); //C
g_2d.draw(tuxing); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第4题:
import java.awt.*;
import javax.swing.*;
class Imagecanvas extends Canvas {
Toolkit tool;
Image image;
Imagecanvas() {
setSize(200,200);
tool=getToolkit(); //A
image=tool.getImage("唐老鸭.jpg"); //B
}
public void paint(Graphics g) {
g.drawImage(image,10,10,image.getWidth(this),image.getHeight(this),this);
g.drawString(12,34,"唐老鸭"); //C
g.drawString("唐老鸭",12,34); //D
}
}
{correctAnswer='C'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
import java.awt.geom.*;
public class E {
public static void main(String args[]) {
Ellipse2D ellipse=new Ellipse2D.Double(40,15,20,20);
Rectangle2D rect =new Rectangle2D.Double(30,15,20,20);
boolean boo = ellipse.intersects(rect);
System.out.println(boo);//【代码】
}
}
{correctAnswer='true'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
import java.awt.geom.*;
public class E {
public static void main(String args[]) {
Ellipse2D ellipse=new Ellipse2D.Double(0,0,100,100);
Rectangle2D rect =new Rectangle2D.Double(40,15,20,20);
boolean boo = ellipse.contains(rect);
System.out.println(boo);//【代码】
}
}
{correctAnswer='true'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
import java.awt.geom.*;
public class E {
public static void main(String args[]) {
Ellipse2D ellipse=new Ellipse2D.Double(10,10,100,80);
int x= (int)ellipse.getCenterX();
int y= (int)ellipse.getCenterY();
System.out.printf("%d:%d",x,y);//【代码】
}
}
{correctAnswer='60:50'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
import java.awt.geom.*;
public class E {
public static void main(String args[]) {
Ellipse2D ellipse=new Ellipse2D.Double(10,8,100,80);
int x= (int)ellipse.getX();
int y= (int)ellipse.getY();
System.out.printf("%d:%d",x,y);//【代码】
}
}
{correctAnswer='10:8'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
import java.awt.geom.*;
public class E {
public static void main(String args[]) {
Ellipse2D ellipse=new Ellipse2D.Double(10,8,100,80);
int w= (int)ellipse.getWidth();
int h= (int)ellipse.getHeight();
System.out.printf("%d:%d",w,h);//【代码】
}
}
{correctAnswer='100:80'}

第15章

选择题

1
2
3
4
5
6
7
8
9
10

题库中第1题:
下列哪些叙述是正确的?(多选)
A.ArrayList的public void add(int index,E element)方法的执行效率低于LinkedList的效率。
B.ArrayList的public void add(int index,E element)方法的执行效率高于LinkedList的效率。
C.ArrayList的public E get(int index)方法的执行效率低于LinkedList的效率。
D.ArrayList的public E get(int index)方法的执行效率效率高于LinkedList的效率


{correctAnswer='AD'}
1
2
3
4
5
6
7
8
9

题库中第2题:
下列哪些叙述是正确的?(多选)
A.ArrayList的public E remove(int index)方法的执行效率低于LinkedList的效率。
B.ArrayList的public E remove(int index)方法的执行效率高于LinkedList的效率。
C.ArrayList的public E get(int index)方法的执行效率低于LinkedList的效率。
D.ArrayList的public E get(int index)方法的执行效率效率高于LinkedList的效率。

{correctAnswer='AD'}
1
2
3
4
5
6
7
8
9

题库中第3题:
哪些叙述是正确的?(多选)
A. LinkedList类不是线程安全的,即提供的添加,删除操作都不是同步(synchronized)的。
B. ArrayList类不是线程安全的,即提供的添加,删除操作都不是同步(synchronized)的。
C. Vector类是线程安全的,即提供的添加,删除操作都是同步(synchronized)的。
D. Stack类是线程安全的,即提供的压栈,弹栈操作都是同步(synchronized)的。

{correctAnswer='CD'}
1
2
3
4
5
6
7
8
9

题库中第4题:
哪个叙述是错误的?
A. LinkedList实现了List接口。
B. Stack实现了List接口。
C. ArrayList实现了List接口。
D. TreeSet实现了List接口。

{correctAnswer='D'}
1
2
3
4
5
6
7
8
9

题库中第5题:
下列哪个是LinkedList有,但ArrayList类没有的方法。
A.boolean add(Object o)方法。
B.void add(int index,Object o)方法
C.boolean remove(Object o)方法
D.E removeLast()方法。

{correctAnswer='D'}

判断题

1
2
3
4

题库中第1题:
LinkedList<String> list = new LinkedList<String>();创建了一个空链表list。
{correctAnswer='正确'}
1
2
3
4
5

题库中第2题:
使用LinkedList<E>泛型类声明、创建链表时,必须要指定E的具体类型,
然后链表就可以使用add(E obj)方法向链表依次增加节点。。
{correctAnswer='正确'}
1
2
3
4
5

题库中第3题:
链表(LinkedList)的public boolean add(E e)方法将指定的元素追加到此链表的末尾。
这种方法相当于addLast(E e)。
{correctAnswer='正确'}
1
2
3
4

题库中第4题:
链表对象可以使用iterator()方法获取一个Iterator对象。
{correctAnswer='正确'}
1
2
3
4

题库中第5题:
ArrayList和LinkedList的区别是:一个使用顺序结构,一个使用链式结构。
{correctAnswer='正确'}
1
2
3
4

题库中第6题:
Stack<String> stack = new Stack<String>();创建了一个空堆栈stack
{correctAnswer='正确'}
1
2
3
4

题库中第7题:
堆栈(Stack)的public E peek()方法获取堆栈顶端的数据,但不删除该数据。
{correctAnswer='正确'}
1
2
3
4

题库中第8题:
HashMap<K,V>对象采用顺序表这种数据结构存储数据。
{correctAnswer='错误'}
1
2
3
4

题库中第9题:
HashMap<K,V>对象采用散列表这种数据结构存储数据。
{correctAnswer='正确'}
1
2
3
4

题库中第10题:
TreeSet采用树结构存储数据。
{correctAnswer='正确'}

挑错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第1题:
下列ABCD注释标注的哪行代码有错误?
import java.util.*;
public class E {
public static void main(String args[]) {
LinkedList<Integer> linkedList = new LinkedList<Integer>();
ArrayList<Integer> arryList = new ArrayList<Integer>();
linkedList.add("1"); //A
arryList.add(new Integer(1)); //B
arryList.add(2); //C
linkedList.add(100); //D
}
}
{correctAnswer='A'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第2题:
下列ABCD注释标注的哪行代码有错误?
import java.util.*;
public class E {
public static void main(String args[]) {
List<Integer> linkedList = new LinkedList<Integer>(); //A
List<Integer> arryList = new ArrayList<Integer>(); //B
List<Integer> stack = new Stack<Integer>(); //C
List<Integer> set = new TreeSet<Integer>(); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第3题:
下列ABCD注释标注的哪行代码有错误?
import java.util.*;
public class E {
public static void main(String args[]) {
LinkedList<Integer> linkedList = new LinkedList<Integer>(); //A
ArrayList<Integer> arryList = new ArrayList<Integer>(); //B
linkedList.add(1);
linkedList.add(2);
arryList.add(1);
int m = linkedList.removeLast(); //C
int n = arryList.removeLast(); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13

题库中第4题:
下列ABCD注释标注的哪行代码有错误?
import java.util.*;
public class E {
public static void main(String args[]) {
Map<String,String> map = new HashMap<String,String>(); //A
Set<Integer> treeSet = new TreeSet<Integer>(); //B
Map<String,String> treeMap = new TreeMap<String,String>(); //C
List<char> list = new LinkedList<char>(); //D
}
}
{correctAnswer='D'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第5题:
import java.util.*;
public class E {
public static void main(String args[]) {
Map<Integer,String> map = new HashMap<Integer,String>();
map.put(1,"hello"); //A
map.put('a',"hello"); //B
Map<Float,String> mapTwo = new HashMap<Float,String>();
mapTwo.put(1.2F,"hello"); //C
mapTwo.put(1F,"hello"); //D

}
}
{correctAnswer='B'}

读程题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第1题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
List<String> list=new LinkedList<String>();
list.add("hello");
list.add("你好");
Iterator<String> iter=list.iterator();
String s=iter.next();
s=iter.next();
System.out.println(s);//【代码】
}
}
{correctAnswer='你好'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

题库中第2题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
List<String> list=new LinkedList<String>();
list.add("hello");
list.add("你好");
list.add("java");
String s = list.remove(0);
s = list.remove(0);
System.out.printf("%d:%s",list.size(),s);//【代码】
}
}
{correctAnswer='1:你好'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第3题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
Stack<Integer> stack=new Stack<Integer>();
stack.push(1);
stack.push(2);
int m = stack.pop();
System.out.printf("%d:%d",stack.size(),m);//【代码】
}
}
{correctAnswer='1:2'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第4题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
Stack<Integer> stack=new Stack<Integer>();
stack.push(1);
stack.push(100);
int m = stack.peek();
System.out.printf("%d:%d",stack.size(),m);//【代码】
}
}
{correctAnswer='2:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

题库中第5题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
HashMap<Integer,String> hashMap = new HashMap<Integer,String>() ;
hashMap.put(1,"boy");
hashMap.put(2,"girl");
hashMap.put(3,"java");
String s = hashMap.get(3);
System.out.printf("%d:%s",hashMap.size(),s);//【代码】
}
}
{correctAnswer='3:java'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第6题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
TreeSet<Integer> mytree=new TreeSet<Integer>();
mytree.add(100);
mytree.add(12);
mytree.add(30);
mytree.add(9);
int m = mytree.first();
int n = mytree.last();
System.out.printf("%d:%d",m,n);//【代码】
}
}
{correctAnswer='9:100'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

题库中第7题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
TreeSet<Integer> mytree=new TreeSet<Integer>();
mytree.add(100);
mytree.add(12);
mytree.add(30);
mytree.add(30);
mytree.add(9);
mytree.add(9);
System.out.printf("%d", mytree.size()); //【代码】
}
}
{correctAnswer='4'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

题库中第8题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
TreeMap<Integer,String> treemap= new TreeMap<Integer,String>();
treemap.put(12,"hello");
treemap.put(1,"java");
treemap.put(1,"你好");
System.out.printf("%d", treemap.size()); //【代码】
}
}
{correctAnswer='2'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

题库中第9题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
TreeMap<Integer,String> treemap= new TreeMap<Integer,String>();
treemap.put(12,"hello");
treemap.put(1,"java");
treemap.put(5,"你好");
treemap.put(3,"home");
int m =treemap.firstKey();
int n =treemap.lastKey();
String s1 =treemap.get(m);
String s2 =treemap.get(n);
System.out.printf("%s:%s", s1,s2); //【代码】
}
}
{correctAnswer='java:hello'}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

题库中第10题:
给出下列【代码】注释标注的代码的输出结果。
import java.util.*;
public class E {
public static void main(String args[]) {
TreeMap<Integer,String> treemap= new TreeMap<Integer,String>();
treemap.put(12,"d");
treemap.put(1,"b");
treemap.put(5,"r");
treemap.put(3,"i");
Collection<String> cn =treemap.values();
Iterator<String> iterator = cn.iterator();
String s1 =iterator.next();
String s2 =iterator.next();
String s3 =iterator.next();
String s4 =iterator.next();
System.out.printf("%s%s%s%s", s1,s2,s3,s4); //【代码】
}
}
{correctAnswer='bird'}