<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>

            java期末考試試題及答案

            時間:2024-10-11 14:16:03 SUN認證 我要投稿
            • 相關推薦

            2016年java期末考試試題及答案

              1.請看下列代碼:

            2016年java期末考試試題及答案

              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);

              System.out.println(a+","+b);

              }

              public static void operator(StringBuffer x,StringBuffer y){

              x.append(y);

              y=x;

              }

              }

              輸出的結果是:()。

              A.A,B

              B.A,A

              C.B,B

              D.AB,B

              正確答案:D

              3.下列代碼的輸出結果是: ()。

              public class A {

              public void info(){

              System.out.println("A info");

              }

              }

              public class B extends A{

              public void info(){

              System.out.println("B info");

              }

              public static void main(String[] args) {

              B b=new B();

              A a=b;

              a.info();

              }

              }

              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();

              System.out.print(Base.FOO);

              System.out.print(Sub.FOO);

              System.out.print(b.FOO);

              System.out.print(s.FOO);

              System.out.print(((Base) s).FOO);

              }

              }

              class Sub extends Base {

              public static final String FOO = "bar";

              }

              A.foofoofoofoofoo

              B.foobarfoobarbar

              C.foobarfoofoofoo

              D.foobarfoobarfoo

              正確答案: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 < arr.length - 1; i++) {

              boolean isSwap = false;

              空白處

              if (!isSwap)

              break;

              }

              下列選項中,空白處可以填入的代碼是:()。//每輪比較結束把最小的放在前面

              A. for (int j = arr.length - 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 = arr.length - 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< arr.length; 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< arr.length; 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 = str.indexOf(str1, index)) != -1) {

              System.out.print(index+””);

              index += str1.length();

              }

              控制臺輸出的結果是:()。

              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() {

              System.out.println("Super.f()");

              }

              public void g() {

              f();

              }

              public void k() {

              f();

              }

              }

              public class Sub extends Super {

              private void f() {

              System.out.println("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. 下列數組聲明語句中,錯誤的是:()。

              A.int[] arr = new int[8];

              B.int[] arr = new int[8]{};

              C.int[] arr = {};

              D.int[] 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類的是()。

              A.public class Employee extends Info implements Data {

              public void load() { /*do something*/ }

              }

              B.public class Employee implements Info extends Data {

              public void load() { /*do something*/ }

              }

              C.public class Employee implements Info extends Data {

              public void Data.load() { /*d something */ }

              public void load() { /*do something */ }

              }

              D.public class Employee extends Info implements Data {

              public void load() { /*do something */ }

              public void Info.load() { /*do something*/ }

              }

              正確答案:A

              14.下列代碼編譯和運行的結果是()。

              public class A {

              public void start() {

              System.out.println("TestA");

              }

              }

              public class B extends A {

              public void start() {

              System.out.println("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() {

              System.out.print("A()");

              System.out.println(a);

              }

              }

              class B extends A {

              private int a = 200;

              B() {

              System.out.print("B()");

              System.out.println(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 = test.split("\\d");

              for (String s : tokens)

              System.out.print(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 的方法

              D.Java線程包括5個狀態,線程的創建,可運行,運行,阻塞和消亡

              正確答案:C

              18.下列代碼的輸出結果是()。

              boolean b=true?false:true==true?false:true;//b=tuer?false:false

              System.out.println(b);

              A.true

              B.false

              C.null

              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;

              System.out.println("s=" + s);

              }

              }

              A.s=14

              B.s=16

              C.s=10

              D.編譯失敗

              正確答案:D

              20. 運行下面的程序:

              String[] fileNames = { "abc.txt", "bcd.exe", "cde.exe", "def.dat","efg.exe" };

              for (String fileName : fileNames) {

              if (fileName.endsWith(".exe")) {

              System.out.print(fileName.substring(0, fileName

              .lastIndexOf(".exe"))+" ");

              }

              }

              控制臺的輸出結果是:()。

              A. bcd. cde. efg.

              B. bc cd ef

              C. bcd.exe cde.exe efg.exe

              D. bcd cde efg

              正確答案:D

              21.下列代碼的作用說法不正確的是:()。

              class Card implements java.io.Serializable{}

              A.開啟序列化功能,使得Card類的對象可以存儲到文件中

              B.開啟序列化功能,使得Card類的對象可以在網絡上傳輸

              C.使得Card類的子類的對象可以被序列化

              D.導致Card的子類的對象不可以被反序列化

              正確答案:D

              22. 運行下列代碼,輸出為false的是:()。

              A. String st1 = "abc";

              System.out.println("abc" == st1);

              B. String st2 = "abc";

              System.out.println(st2.equals(new String("abc")));

              C. Integer i = 100; //

              System.out.println(100 == i);

              D. ArrayList list = new ArrayList();

              System.out.println(list.contains(null));

              正確答案:D

              23.運行下列程序:

              String str = "**java***java*****java*";

              String str1 = "java";

              int index = 0;

              while ((index = str.indexOf(str1, index)) != -1) {

              System.out.print(index+””);

              index += str1.length();

              }

              控制臺輸出的結果是:()。

              A. 1 8 17

              B. 2 9 18

              C. 5 12 21

              D. 6 13 22

              正確答案:B

              24. 下列代碼中不能正確獲取到Class類的對象的是:()。

              A.String sub = "hello";

              Class c1 = sub.getClass();

              B.Class c2 = int.TYPE;

              C.Class c1 = Class.forName ("java.lang.Integer");

              D.Button b = new Button();

              Class c1 = b.getClass();

              Class c2 = c1.getSuperclass();

              正確答案:B

              25.URLEncoding是一種應用于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 < bs.length; i++) {

              空白處2

              sb.append("%").append(str);

              }

              System.out.println(sb.toString());

              空白處1及空白處2分別應填入的代碼是()。

              A. byte[] bs = msg.getChars("utf-8");

              和 String str = Integer.toHexString(bs[i]& 0xff).toUpperCase();

              B. byte[] bs = msg.getBytes("utf-8");

              和 String str = Integer.toHexString(bs[i]).toUpperCase();

              C. byte[] bs = msg.getBytes("utf-8");

              和 String str = Integer.toHexString(bs[i] & 0xff).toUpperCase();

              D. byte[] bs = msg.getBytes();

              和 String str = Integer.toHexString(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");

              System.out.println(t.name);

              }

              }

              A.null

              B.Tom

              C.Jack

              D." "

              正確答案:B

              27. 下列屬于不合法Java標識符的是()。

              A._avaj

              B.5save

              C.Avaj

              D.$80

              正確答案:B

              28.下列代碼的輸出結果是()。

              public static void main(String[] args) {

              Runnable r = new Runnable() {

              public void run() {

              System.out.print("Cat");

              }

              };

              Thread t = new Thread(r) {

              public void run() {

              System.out.print("Dog");

              }

              };

              t.start();

              }

              A.Cat

              B.Dog

              C.沒有任何輸出

              D.拋出運行時異常

              正確答案:B

              29. 下面關于final說法正確的是:()。

              A.final修飾類時,該類能被繼承。

              B.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) {

              <插入代碼>

              System.out.println(s);

              }

              如果程序輸出的結果是4247,那么在<插入代碼>處應該填入代碼是()。

              A.String s = "123456789";

              s = (s-"123").replace(1,3,"24") - "89";

              B.StringBuffer s = new StringBuffer("123456789");

              s.delete(0,3).replace( 1,3, "24").delete(4,6);

              C.StringBuffer s = new StringBuffer("123456789");

              s.substring(3,6).delete( 1 ,3).insert( 1, "24");

              D.StringBuilder s = new StringBuilder("123456789");

              s.substring(3,6).delete( 1 ,2).insert( 1, "24");

              正確答案:B

              32. 下面關于interface,敘述錯誤的是:()

              A.一個interface可以繼承多個interface

              B.接口中的方法可以由private修飾

              C.interface中可以定義static final 常量

              D.interface中可以無任何方法定義

              正確答案:B

              33.分析如下代碼,輸出結果為()。

              public static void main(String[] args) {

              int i = 0;

              boolean re = false

              re = ((++i) + i == 2) ? true : false;

              System.out.println("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;

              System.out.print(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) {

              System.out.println(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;

              }

              D.int 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 方法重載的方法是()。

              A.public 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("");

              this.rows = rows;

              this.cols = 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 = line.split(",");

              if ( 空白處1 ) {

              throw new IllegalArgumentException("");

              }

              this.rows = rows;

              this.cols = cols;

              data = new double[rows][cols];

              for (int i = 0; i < dataStr.length; i++) {

              ( 空白處2 )

              }

              }

              public Matrix mul(Matrix ma) {

              if ( 空白處3 ) {

              throw new IllegalArgumentException();

              }

              Matrix mc = new Matrix(rows, ma.cols);

              for (int i = 0; i < mc.getRows(); i++) {

              for (int j = 0; j < mc.getCols(); 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++) {

              sb.append(data[i][j]).append(",");

              }

              sb.append(data[i][cols - 1]).append("\n");

              }

              return sb.toString();

              }

              }

              (1). 空白處1()

              A. dataStr.length != (rows-1) * (cols-1)

              B. dataStr.length != (rows-1) * cols

              C. dataStr.length != rows * cols

              D. dataStr.length != rows * (cols-1)

              正確答案:C

              (2). 空白處2()

              A. data[i % cols][i / cols] = Double.parseDouble(dataStr[i]);

              B. data[i/cols][i % cols] = Double.parseDouble(dataStr[i]);

              C. data[i/ rows][i % rows] = Double.parseDouble(dataStr[i]);

              D. data[i % rows][i /rows] = Double.parseDouble(dataStr[i]);

              正確答案:B

              (3). 空白處3()

              A. cols != ma.cols

              B. rows != ma.cols

              C. rows != ma.rows

              D. cols != ma.rows

              正確答案: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. mc.data[i][j] += data[k][j] * ma.data[i][k];

              B. mc.data[i][j] += data[k][i] * ma.data[j][k];

              C. mc.data[i][j] += data[j][k] * ma.data[k][i];

              D. mc.data[i][j] += data[i][k] * ma.data[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=cards.length;

              空白處1

              while (true) {

              Random rd = new Random();

              空白處2

              cardThirteen.add(cards[index]);

              if ( 空白處3 == 13) {

              break;

              }

              }

              空白處4

              while ( 空白處5 ) {

              System.out.println(it.next());

              }

              }

              (1).下列選項中,能填入空白處1的代碼是( )

              A.Set cardThirteen = new HashSet();

              B.Set cardThirteen = new Set();

              C.List cardThirteen = new List();

              D.List cardThirteen = new ArrayList();

              正確答案:A

              (2).下列選項中,能填入空白處2的代碼是( )

              A.index = rd.nextInt();

              B.index = rd.nextInt(5);

              C.index = rd.nextInt(len + 1);

              D.index = rd.nextInt(len);

              正確答案:D

              (3).下列選項中,能填入空白處3的代碼是( )

              A.cardThirteen.size

              B.cardThirteen.length

              C.cardThirteen.length()

              D.cardThirteen.size()

              正確答案:D

              (4).下列選項中,能填入空白處4的代碼是( )

              A.Iterator it = cardThirteen.iterator();

              B.Iterator it = cardThirteen.next();

              C.Iterators it = cardThirteen.iterator();

              D.Iterators it = cardThirteen.nexts();

              正確答案:A

              (5).下列選項中,能填入空白處5的代碼是( )

              A.it.hasNext()

              B.it.hasNexts ()

              C.it.next ()

              D.it.nexts()

              正確答案:A


            【java期末考試試題及答案】相關文章:

            JAVA模擬試題及答案10-18

            java面試題及答案11-01

            java基礎筆試題及答案10-18

            java考試試題及答案10-25

            2017年Java筆試題及答案08-03

            2024年Java筆試題及答案10-29

            java認證考試試題及答案07-21

            java面試題2017及答案06-08

            高級Java面試題及答案201609-18

            2017年JAVA考試試題及答案08-30

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看