每个人都曾试图在平淡的学习、工作和生活中写一篇文章。写作是培养人的观察、联想、想象、思维和记忆的重要手段。范文怎么写才能发挥它最大的作用呢?下面是小编帮大家整理的优质范文,仅供参考,大家一起来看看吧。
java期末考试试题及答案篇一
1.请看下列代码:
class classa {}
class classb extends classa {}
class classc extends classa {}
public class test{
public static void main(string[] args) {
classa p0 = new classa();
classb p1 = new classb();
classc p2 = new classc();
classa p3 = new classb();
classa p4 = new classc();
<插入代码>
}
}
可以在<插入代码>处,填入的代码正确的是()
a.p0 = p1;
b.p1 =p2;
c.p2 = p4;
d.p2 = (classc)p1;
正确答案:a
2.运行下面程序:
public class foo {
public static void main(string[] args) {
stringbuffer a=new stringbuffer("a");
stringbuffer b=new stringbuffer("b");
operator(a,b);
n(a+","+b);
}
public static void operator(stringbuffer x,stringbuffer y){
(y);
y=x;
}
}
输出的结果是:()。
a.a,b
b.a,a
c.b,b
,b
正确答案:d
3.下列代码的输出结果是: ()。
public class a {
public void info(){
n("a info");
}
}
public class b extends a{
public void info(){
n("b info");
}
public static void main(string[] args) {
b b=new b();
a a=b;
();
}
}
a.b info
a info
b.a info
b info
c.a info
d.b info
正确答案:d
4.下列代码运行的结果是()。
public class base {
public static final string foo = "foo";
public static void main(string[] args) {
base b = new base();
sub s = new sub();
();
();
();
();
(((base) s).foo);
}
}
class sub extends base {
public static final string foo = "bar";
}
foofoofoo
foobarbar
foofoofoo
foobarfoo
正确答案:d
5.执行下列语句:
int a = 0x9af700; // 00 00 00 10 01 10 10 1111 0111 0000 0000 00
a <<= 2;
变量a的值为:()。
a. 0x26bdc00
b. 0xc6bdc00
c. 0x3fa0000
d. 0x7e02ffff
正确答案:a
6. 下面的代码用于对数组arr实现冒泡排序:【1,2,3,4,5】
for (int i = 0; i < - 1; i++) {
boolean isswap = false;
空白处
if (!isswap)
break;
}
下列选项中,空白处可以填入的代码是:()。//每轮比较结束把最小的放在前面
a. for (int j = - 1; j > i; j--) {
if (arr[j] < arr[j - 1]) {
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
isswap = true;
}
}
b. for (int j = - 1; j > 0; j--) {
if (arr[j] < arr[j - 1]) {
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
isswap = true;
}
}
c. for (int j = i + 1; j< ; j++) {
if (arr[j] < arr[j - 1]) {
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
isswap = true;
}
}
d. for (int j = i; j< ; j++) {
if (arr[j] < arr[j - 1]) {
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
isswap = true;
}
}
正确答案:a
7.下列语句创建对象的总个数是:()。
string s=”a”+”b”+”c”+”d”+”e”;
a.1
b.2
c.3
d.4
正确答案:a
8.运行下列程序:
string str = "**oracle***oracle*****oracle***";
string str1 = "oracle";
int index = 0;
while ((index = f(str1, index)) != -1) {
(index+””);
index += ();
}
控制台输出的结果是:()。
a.1 10 21
b.2 11 22
c.3 13 23
d.5 13 22
正确答案:b
9. 下列表达式中,可以得到精确结果的是()。
a. double d1 = 3.0 - 2.6; 0.4
b. double d4 = 2.5 * 1.5;
c. double d2 = 30/300;
d. double d3 = 1/2 + 0.5;
正确答案:b
10.类super及sub定义如下:
public class super {
private void f() {
n("super.f()");
}
public void g() {
f();
}
public void k() {
f();
}
}
public class sub extends super {
private void f() {
n("sub.f()");
}
public void k() {
f();
}
}
运行下列语句:
super obj = new sub();
obj.g();
obj.k();
输出的结果是:()。
a. sub.f()
sub.f()
b. sub.f()
super.f()
c. super.f()
sub.f()
d. super.f()
super.f()
正确答案:c
11. 下列数组声明语句中,错误的是:()。
[] arr = new int[8];
[] arr = new int[8]{};
[] arr = {};
[] arr = new int[]{};
正确答案:b
12.执行下列语句:
int num=~3+2; 变量num的值为()。
a.-3
b.3
c.-2
d.-1
正确答案:c
13.请看下列代码:
interface data { public void load(); }
abstract class info { public abstract void load(); }
下列选项中,能正确使用data接口和info类的是()。
class employee extends info implements data {
public void load() { /*do something*/ }
}
class employee implements info extends data {
public void load() { /*do something*/ }
}
class employee implements info extends data {
public void () { /*d something */ }
public void load() { /*do something */ }
}
class employee extends info implements data {
public void load() { /*do something */ }
public void () { /*do something*/ }
}
正确答案:a
14.下列代码编译和运行的结果是()。
public class a {
public void start() {
n("testa");
}
}
public class b extends a {
public void start() {
n("testb");
}
public static void main(string[] args) {
((a) new b()).start();
}
}
a.输出:testa
b.输出:testb
c.输出:testa testb
d.编译错误
正确答案:b
15.类a,b的定义如下:
class a {
private int a = 100;
a() {
("a()");
n(a);
}
}
class b extends a {
private int a = 200;
b() {
("b()");
n(a);
}
}
运行下面的代码:new b();
输出的结果是:()。
a. a() 100
b() 200
b. a() 200
b() 200
c. b() 200
a() 100
d. b() 200
a() 200
正确答案:a
16.下列代码的输出结果是()
public static void main(string[] args) {
string test = "a1b2c3";
string[] tokens = ("\\d");
for (string s : tokens)
(s + " ");
}
a.a b c
b.1 2 3
c.a1b2c3
d.a1 b2 c3
正确答案:a
17. 关于java线程说法错误的是()。
a.创建线程的有2种方式,方式1是继承thread类,方式2是实现 runnable 接口
b.解决线程安全使用问题 synchronized关键字,使得同一时间只有一个线程执行该关键字限定的代码段
c.线程间通信所使用的方法有,wait,notify,notifyall,它们都是 thread 的方法
线程包括5个状态,线程的创建,可运行,运行,阻塞和消亡
正确答案:c
18.下列代码的输出结果是()。
boolean b=true?false:true==true?false:true;//b=tuer?false:false
n(b);
d.空字符串
正确答案:b
19.请看下列代码编译和运行的结果是()。
interface declarestuff {
public static final int easy = 3;
void dostuff(int t);// public rabstract
}
public class testdeclare implements declarestuff {
public static void main(string[] args) {
int x = 5;
new testdeclare().dostuff(++x);
}
void dostuff(int s) {
s += easy + ++s;
n("s=" + s);
}
}
a.s=14
b.s=16
c.s=10
d.编译失败
正确答案:d
20. 运行下面的程序:
string[] filenames = { "", "", "", "","" };
for (string filename : filenames) {
if (th(".exe")) {
(ing(0, filename
.lastindexof(".exe"))+" ");
}
}
控制台的输出结果是:()。
a. bcd. cde. efg.
b. bc cd ef
c.
d. bcd cde efg
正确答案:d
21.下列代码的作用说法不正确的是:()。
class card implements izable{}
a.开启序列化功能,使得card类的对象可以存储到文件中
b.开启序列化功能,使得card类的对象可以在网络上传输
c.使得card类的子类的对象可以被序列化
d.导致card的子类的对象不可以被反序列化
正确答案:d
22. 运行下列代码,输出为false的是:()。
a. string st1 = "abc";
n("abc" == st1);
b. string st2 = "abc";
n((new string("abc")));
c. integer i = 100; //
n(100 == i);
d. arraylist list = new arraylist();
n(ns(null));
正确答案:d
23.运行下列程序:
string str = "**java***java*****java*";
string str1 = "java";
int index = 0;
while ((index = f(str1, index)) != -1) {
(index+””);
index += ();
}
控制台输出的结果是:()。
a. 1 8 17
b. 2 9 18
c. 5 12 21
d. 6 13 22
正确答案:b
24. 下列代码中不能正确获取到class类的对象的是:()。
sub = "hello";
class c1 = suss();
c2 = ;
c1 = e ("r");
b = new button();
class c1 = ss();
class c2 = erclass();
正确答案:b
oding是一种应用于http协议的编码方式,字符串“你好”基于utf-8的urlencoding编码为: “%e4%bd%a0%e5%a5%bd”
其中e4、bd、a0为字符“你”的utf-8编码的十六进制形式(3个字节),而e5、a5、bd为字符“好”的utf-8编码的十六进制形式。
下面的代码用程序的方式输出字符串“你好”的基于utf-8的urlencoding序列:
string msg = "你好";
空白处1
stringbuilder sb = new stringbuilder();
for (int i = 0; i < ; i++) {
空白处2
("%").append(str);
}
n(ng());
空白处1及空白处2分别应填入的代码是()。
a. byte[] bs = rs("utf-8");
和 string str = tring(bs[i]& 0xff).touppercase();
b. byte[] bs = es("utf-8");
和 string str = tring(bs[i]).touppercase();
c. byte[] bs = es("utf-8");
和 string str = tring(bs[i] & 0xff).touppercase();
d. byte[] bs = es();
和 string str = tring(bs[i]).touppercase();
正确答案:c
26.程序执行的结果是()。
public class test {
string name="tom";
public test(string name){
name=name;
}
public static void main(string [] args){
test t = new test("jack");
n();
}
}
d." "
正确答案:b
27. 下列属于不合法java标识符的是()。
a._avaj
b.5save
d.$80
正确答案:b
28.下列代码的输出结果是()。
public static void main(string[] args) {
runnable r = new runnable() {
public void run() {
("cat");
}
};
thread t = new thread(r) {
public void run() {
("dog");
}
};
();
}
c.没有任何输出
d.抛出运行时异常
正确答案:b
29. 下面关于final说法正确的是:()。
修饰类时,该类能被继承。
修饰方法时,该方法能被重写。
c.当使用static final 修饰的常量时,将采用编译期绑定的方式。
d.当使用final和abstract共同修饰一个类时,final应至于abstract之前。
正确答案:c
30. 下面关于final说法错误的是:()
a. final修饰类时,该类不能被继承。
b. final修饰方法时,该方法不能被重写。
c. 当引用到使用static final 修饰的常量时,将采用编译期绑定的方式。
d. 当使用final和abstract共同修饰一个类时,final应至于abstract之前。
正确答案:d
31.请看下列代码:
public static void main(string[] args) {
<插入代码>
n(s);
}
如果程序输出的结果是4247,那么在<插入代码>处应该填入代码是()。
s = "123456789";
s = (s-"123").replace(1,3,"24") - "89";
buffer s = new stringbuffer("123456789");
(0,3).replace( 1,3, "24").delete(4,6);
buffer s = new stringbuffer("123456789");
ing(3,6).delete( 1 ,3).insert( 1, "24");
builder s = new stringbuilder("123456789");
ing(3,6).delete( 1 ,2).insert( 1, "24");
正确答案:b
32. 下面关于interface,叙述错误的是:()
a.一个interface可以继承多个interface
b.接口中的方法可以由private修饰
erface中可以定义static final 常量
ace中可以无任何方法定义
正确答案:b
33.分析如下代码,输出结果为()。
public static void main(string[] args) {
int i = 0;
boolean re = false
re = ((++i) + i == 2) ? true : false;
n("i=" + i + ",re="+re);
}
a.i=1,re=true
b.i=0,re=true
c.i=1,re=false
d.i=0,re=false
正确答案:a
34. 下列数组声明语句中,错误的是:()。
a. int[] arr = new int[]{};
b. int[] arr = new int[];
c. int[] arr = {};
d. int[][] arr = new int[2][]
正确答案:b
35.下列代码的运行结果是()
public static void main(string[] args) {
string str = "420";
str += 42;
(str);
}
a.42
b.420
c.462
d.42042
正确答案:d
36.所谓“水仙花”数是一个整数等于各位数字立方的和,例如:153 = 1*1*1+5*5*5+3*3*3,下面的.程序用于输出2~1000内的水仙花数:
for (int n = 2; n <= 1000; n++) {
空白处
if (s == n) {
n(n);
}
}
下列选项中,空白处可以填入的代码是:()。
a. int s = 0, n1 = n;
while (n1 > 0) {
int t = n1 % 10;
s += t * t * t;
n1 /= 10;
}
b. int s = 0, n1 = n;
while (n1 > 0) {
int t = n1 / 10;
s+= t * t * t;
n1 %= 10;
}
c. int s = 0;
for(int n1 = n; n1>0; n1 /= 10) {
int t = n1%10;
s += t * t * t;
}
s = 0;
for(int n1 = n; n1>0; n1 %= 10) {
int t = n1 / 10;
s += t * t * t;
}
正确答案:ac
37. 下面的方法属于stringbuffer的是:()。
a. size
b. insert
c. delete
d. length
正确答案:bcd
38.类super的定义如下:
class a {
protected void f() throws ioexception {
………
}
}
下列代码段中,没有编译错误的是:()。
a. class b extends a {
public void f() throws exception {
………
}
}
b. class b extends a {
public void g() throws ioexception {
f();
}
}
c. class b extends a {
public void g() {
try {
f();
………
}catch(exception e) {
………
}catch(ioexception e1) {
………
}
}
}
d. class b extends a {
public void g() {
try {
f();
}catch(ioexception e) {
throw new runtimeexception(e);
}
}
}
正确答案:bd
39.查看如下代码:
public class foo {
public void method(string str,int age){}
}
下列选项中,和 foo 类中 method 方法重载的方法是()。
int method(string str,int age){}
b. public void method(int year,string s){}
c. public int method(int year,string s){}
d. public int method(string str){}
正确答案:bcd
40. 下列关于java的说法,错误的是()。
a. java语言是纯粹的面向对象的语言。
b. java程序的运行必须有java虚拟机(jvm)的支持。
c. java语言支持指针。
d. java语言支持多重继承。
正确答案:cd
41.矩阵是指纵横排列的数据表格,最早来自于方程组的系数及常数所构成的方阵,如:
a11 a12... a1n
a21 a22... a2n
... ... ...
am1 am2... amn
矩阵乘积规则示例如下:
两个矩阵a和b可以相乘的条件是a矩阵的列数和b矩阵的行数相同,例如:
假设矩阵a为“2行3列”:
a11 a12 a13
a21 a22 a23
矩阵b为“3行2列”:
b11 b12
b21 b22
b31 b32
a和b可以相乘,乘积矩阵为:
a11*b11+a12*b21+a13*b31 a11*b12+a12*b22+a13*b32
a21*b11+a22*b21+a23*b31 a21*b12+a22*b22+a23*b32
matrix类的定义如下:
public class matrix {
private double[][] data;
private int rows;
private int cols;
public matrix(int rows, int cols) {
if (rows <= 0 || cols <= 0)
throw new illegalargumentexception("");
= rows;
= cols;
data = new double[rows][cols];
}
public matrix(int rows, int cols, string line) {
if (rows <= 0 || cols <= 0 || line == null)
throw new illegalargumentexception("");
string[] datastr = (",");
if ( 空白处1 ) {
throw new illegalargumentexception("");
}
= rows;
= cols;
data = new double[rows][cols];
for (int i = 0; i < ; i++) {
( 空白处2 )
}
}
public matrix mul(matrix ma) {
if ( 空白处3 ) {
throw new illegalargumentexception();
}
matrix mc = new matrix(rows, );
for (int i = 0; i < s(); i++) {
for (int j = 0; j < s(); j++) {
for ( 空白处4 ) {
空白处5
}
}
}
return mc;
}
public int getrows() {
return rows;
}
public int getcols() {
return cols;
}
public string tostring() {
stringbuilder sb = new stringbuilder();
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols - 1; j++) {
(data[i][j]).append(",");
}
(data[i][cols - 1]).append("\n");
}
return ng();
}
}
(1). 空白处1()
a. != (rows-1) * (cols-1)
b. != (rows-1) * cols
c. != rows * cols
d. != rows * (cols-1)
正确答案:c
(2). 空白处2()
a. data[i % cols][i / cols] = ouble(datastr[i]);
b. data[i/cols][i % cols] = ouble(datastr[i]);
c. data[i/ rows][i % rows] = ouble(datastr[i]);
d. data[i % rows][i /rows] = ouble(datastr[i]);
正确答案:b
(3). 空白处3()
a. cols !=
b. rows !=
c. rows !=
d. cols !=
正确答案:d
(4). 空白处4()
a. int k = 0; k < cols; k++
b. int k = 0; k
c. int k = 0; k
d. int k = 0; k
正确答案:a
(5). 空白处5()
a. [i][j] += data[k][j] * [i][k];
b. [i][j] += data[k][i] * [j][k];
c. [i][j] += data[j][k] * [k][i];
d. [i][j] += data[i][k] * [k][j];
正确答案:d
42.下面的程序用于从54张扑克牌中,随机选出13张不同的扑克牌。
public static void main(string[] args) {
string[] cards = { "红桃3", "红桃4", "红桃5", "红桃6", "红桃7",
"红桃8","红桃9","红桃10","红桃j","红桃q","红桃k","红桃a",
"黑桃3", "黑桃4", "黑桃5", "黑桃6", "黑桃7","黑桃8","黑桃9",
"黑桃10","黑桃j","黑桃q","黑桃k","黑桃a","红方块3", "红方块4",
"红方块5", "红方块6", "红方块7","红方块8","红方块9","红方块10",
"红方块j","红方块q","红方块k","红方块a","黑方块3", "黑方块4",
"黑方块5", "黑方块6", "黑方块7","黑方块8","黑方块9","黑方块10",
"黑方块j","黑方块q","黑方块k","黑方块a"};
int len=;
空白处1
while (true) {
random rd = new random();
空白处2
(cards[index]);
if ( 空白处3 == 13) {
break;
}
}
空白处4
while ( 空白处5 ) {
n(());
}
}
(1).下列选项中,能填入空白处1的代码是( )
cardthirteen = new hashset();
cardthirteen = new set();
cardthirteen = new list();
cardthirteen = new arraylist();
正确答案:a
(2).下列选项中,能填入空白处2的代码是( )
= t();
= t(5);
= t(len + 1);
= t(len);
正确答案:d
(3).下列选项中,能填入空白处3的代码是( )
()
()
正确答案:d
(4).下列选项中,能填入空白处4的代码是( )
or it = or();
or it = ();
ors it = or();
ors it = s();
正确答案:a
(5).下列选项中,能填入空白处5的代码是( )
t()
ts ()
c. ()
()
正确答案:a
s("content_relate");
【2016年java期末考试试题及答案】相关文章:
1.2017年java考试试题及答案
2.java认证考试试题及答案
3.2016年java考试试题及答案
4.2017最新java考试试题及答案
5.2016年大学java期末考试试题
6.2017年java期末考试试题
7.《java程序设计》期末考试试题
8.2016年《java程序设计》期末考试试题

一键复制