现在的位置: 首页 > 综合 > 正文

java基础试题3(选择)

2017年10月12日 ⁄ 综合 ⁄ 共 5961字 ⁄ 字号 评论关闭

第四组:

1.         要从文件"file.dat"中读出第10个字节到变量c,下列哪个方法适合?
()

A FileInputStream in=new FileInputStream("file.dat"); in.skip(9); int c=in.read();

B FileInputStream in=new FileInputStream("file.dat"); in.skip(10); int c=in.read();

C FileInputStream in=new FileInputStream("file.dat"); int c=in.read();

D RandomAccessFile in=new RandomAccessFile("file.dat"); in.skip(9); int c=in.readByte();

2.         Java编程所必须的默认引用包为(    )

A. java.sys

B. java.lang

C. java.util

D.以上都不是

3.         下面语句在编译时不会出现警告或错误的是(   )

A. float f=3.14;

B. char c=”c”;

C. Boolean b=null;

D. int i=10.0;

4.         下面不是合法标识符的是(    )

A. 2ofUS

B. giveMes

C. whataQuiz

D. $d2000_

5.         下面哪一个是合法的数组声明和构造语句(    )

A. int[] ages = [100];

B. int ages = new int[100];

C. int[] ages = new int[100];

D. int() ages = new int(100);

6.         下面说法不正确的是(    )

A. 一个子类的对象可以接收父类对象能接收的消息;

B. 当子类对象和父类对象能接收同样的消息时,它们针对消息产生的行为可能不同;

C. 父类比它的子类的方法更多;

D. 子类在构造函数中可以使用super( )来调用父类的构造函数;

7.         给出下面代码段,
哪行将引起一个编译时错误?(   

1) public class Test {

2)   int n = 0;

3)   int m = 0;

4)   public Test(int a) { m=a; }

5)   public static void main(String arg[]) {

6)     Test t1,t2;

7)     int j,k;

8)     j=3; k=5;

9)     t1=new Test();

10)    t2=new Test(k);

11)  }

12) }

A. 1                 B.
4                 C. 6                 D.
9

8. 下面程序中类ClassDemo中定义了一个静态变量sum,分析程序段的输出结果。(    

class ClassDemo {

   public static int sum=1;

   public ClassDemo() {

      sum = sum + 5;

   }

}

public class ClassDemoTest{

   public static void main(String args[]) {

   ClassDemo demo1=new ClassDemo();

   ClassDemo demo2=new ClassDemo();

   System.out.println(demo1.sum);

   }

}

A. 0                      B. 6                      C. 11                  D. 2

9.下面这些类型的应用,那个不使用Java语言来编写?(    

AJavaScript                     BApplet

CServlet                        DJava Swing

10.     声明成员变量时,如果不使用任何访问控制符(public, protected, private),则以下哪种类型的类不能对该成员进行直接访问(  
  

A)同一类                         B)同一包中的子类

C)同一包中的非子类               D)不同包中的子类

11.     下列哪种异常是检查型异常,需要在编写程序时声明(    

ANullPointerException              BClassCastException

CFileNotFoundException            D) IndexOutOfBoundsException

12.     下面哪个流类属于面向字符的输入流(    )

ABufferedWriter                 BFileInputStream

CObjectInputStream              D) InputStreamReader

13.     下面关于数组声明和初始化的语句那个有语法错误?(  

Aint a1[]={3,4,5};

BString a2[]={"string1","string1","string1"};

CString a3[]=new String(3);

Dint[][] a4=new int[3][3];

14.     下面哪一行代码正确的声明了一个类方法(静态方法)?(      

Apublic int method(int i)

Bprotected method(int i)

Cpublic static method(String s)

Dprotected static void method(Integer i)

15.     下面的方法,当输入为2的时候返回值是多少?   

    public int getValue(int i) {

        int result = 0;

        switch (i) {

            case 1:

                result = result + i;

            case 2:

                result = result + i * 2;

            case 3:

                result = result + i * 3;

        }

        return result;

    }

A0                    B2                    C4                    
D
10

16.     getCustomerInfo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中产生了一个IOException,将会输出什么结果( 
  

    public void getCustomerInfo() {

          try {

              // do something that may cause an Exception

          } catch (java.io.FileNotFoundException  ex){

                System.out.print("FileNotFoundException!");

          } catch (java.io.IOException  ex){

                System.out.print("IOException!");

          } catch (java.lang.Exception  ex){

                System.out.print("Exception!");

          }

      }

AIOException!

BIOException!Exception!

CFileNotFoundException!IOException!

DFileNotFoundException!IOException!Exception!

17.     新建一个流对象,下面哪个选项的代码是错误的?(    

Anew BufferedWriter(new FileWriter("a.txt"));

Bnew BufferedReader(new FileInputStream("a.dat"));

Cnew GZIPOutputStream(new FileOutputStream("a.zip"));

Dnew ObjectInputStream(new FileInputStream("a.dat"));

18.     Java的集合框架中重要的接口java.util.Collection定义了许多方法。选项中哪个方法不是Collection接口所定义的?
  )

Aint size()

Bboolean containsAll(Collection c)

CcompareTo(Object obj)

Dboolean remove(Object obj)

19.     一个线程在任何时刻都处于某种线程状态(thread state,例如运行状态、阻塞状态、就绪状态等。一个线程可以由选项中的哪种线程状态直接到达运行状态?
  )

A)死亡状态

B)阻塞状态(对象lock池内)

C)阻塞状态(对象wait池内)

D)就绪状态

20.     选项中哪一行代码可以替换题目中//add code here而不产生编译错误?(    

public abstract class MyClass {

           public int constInt = 5;

          //add code here

           public void method() {

               }

}

Apublic abstract void method(int a);

Bvalue = value + 5;

Cpublic int method();

Dpublic abstract void anotherMethod() {}

21.     File类是IO包中唯一表示磁盘文件信息的对象,它定义了一些与平台无关的方法来操纵文件。通过调用File类提供的各种方法,我们能够创建、删除文件、重命名文件、判断文件的读写权限及是否存在,设置和查询文件的最近修改时间等。下面的代码片段实现的是什么功能?
  )

File file = new File("C:\\test.dat");

              if (file.exists()) {

                     file.delete();

              }

A)创建C:\test.dat

B)    删除C:\test.dat

C)    打开C:\test.dat文件输出流。

D) 移动C:\test.dat

22.     阅读ShapeCircle两个类的定义。在序列化一个Circle的对象circle到文件时,下面哪个字段会被保存到文件中?
(    )

class Shape {

           public String name;

}

class Circle extends Shape implements Serializable{

       private float radius;

       transient int color;

       public static String type = "Circle";

}

Aname

Bradius

Ccolor

Dtype

23.     下面是PeopleChild类的定义和构造方法,每个构造方法都输出编号。在执行new
Child("mike")
的时候都有哪些构造方法被顺序调用?请选择输出结果 (    )

class People {

       String name;

       public People() {  System.out.print(1); }

       public People(String name) {

              System.out.print(2);

              this.name = name;

       }

}

class Child extends People {

       People father;

       public Child(String name) {

              System.out.print(3);

              this.name = name;

              father = new People(name + ":F");

       }

       public Child(){ System.out.print(4); }

}

A312              B) 32

C)    432              D) 132

24.     下面哪个选项中的代码没有定义内部类,或者错误的定义了内部类? (    )

Apublic Class Line {

      int length;

      Class Point {//内部类代码}

}

B)    public Class Line {

      public Point getPoint() {

         return new Point(){//内部类代码};

      }

}

C)    public Class Line {

              //外部类代码

}

Class Point {//内部类代码}

D) public Class Line {

      public int calcLength() {

         Class Point {//内部类代码}

      }

}

 

25.      list是一个ArrayList的对象,哪个选项的代码填写到//todo delete处,可以在Iterator遍历的过程中正确并安全的删除一个list中保存的对象?
  )

       Iterator it = list.iterator();

       int index = 0;

       while (it.hasNext()){

              Object obj = it.next();

              if (needDelete(obj)) { //needDelete返回boolean,决定是否要删除

           //todo delete

              }

              index ++;

       }

Alist.remove(obj);

Blist.remove(index);

Clist.remove(it.next());

Dit.remove();

抱歉!评论已关闭.