|  | 
 
| 17春学期《JAVA语言程序设计Ⅰ》在线作业1 作业答案请
 
 一、单选题:
 1.下列语句序列执行后,k 的值是(    )。int x=6, y=10, k=5;switch( x%y ){ case 0:  k=x*y;  case 6:  k=x/y;  case 12: k=x-y;  default: k=x*y-x;}          (满分:3)
 A. 60
 B. 54
 C. 0
 D. 5
 2.有下面的类:  public class Example{   public static void main(String args[]){   static int x[] = new int[15];   System.out.println(x[5]);   }   }下面的那些说法是正确的。          (满分:3)
 A. 编译时出错
 B. 运行时出错
 C. 输出0
 D. 输出null
 3.下列程序段执行后t5的结果是(    )。int t1 = 9, t2 = 11, t3=8;int t4,t5;t4 = t1 > t2 ? t1 : t2+ t1;t5 = t4 > t3 ? t4 : t3;          (满分:3)
 A. 8
 B. 20
 C. 11
 D. 9
 4.下面的语句的作用是:(    )。    Vector  MyVector = new  Vector(100,50);          (满分:3)
 A. 创建一个数组类对象MyVector,有100个元素的空间,每个元素的初值为50。
 B. 创建一个向量类对象MyVector,有100个元素的空间,每个元素的初值为50。
 C. 创建一个数组类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。
 D. 创建一个向量类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。
 5.给出下列的代码,哪行在编译时可能会有错误? ① public void modify(    ){ ② int i, j, k; ③ i = 100; ④ while ( i > 0 ){ ⑤ j = i * 2; ⑥ System.out.println (" The value of j is " + j ); ⑦ k = k + 1; ⑧ } ⑨ }          (满分:3)
 A. 4
 B. 6
 C. 7
 D. 8
 6.已知表达式int m[] = {0, 1, 2, 3, 4, 5, 6 };下面哪个表达式的值与数组下标量总数相等?          (满分:3)
 A. m.length(    )
 B. m.length
 C. m.length(    )+1
 D. m.length+1
 7.给出下列代码,则数组初始化中哪项是不正确的? byte[] array1,array2[]; byte array3[][]; byte [][] array4;          (满分:3)
 A. array2 = array1
 B. array2=array3
 C. array2=array4
 D. array3=array4
 8.已知如下代码:boolean m = true;if( m = false )System.out.println("False");elseSystem.out.println("True");执行结果是什么?          (满分:3)
 A. False
 B. True
 C. 编译时出错
 D. 运行时出错
 9.下列程序的功能是在监控台上每隔一秒钟显示一个字符串“Hello”,能够填写在程序中下划线位置,使程序完整并能正确运行的语句是  public class Test implements Runnable{  public static void main(String args[]){  Test t=new Test(    );  Thread tt=new Thread(t);  tt.start(    );  }  public void run(    ){  for(;;){  try{          (满分:3)
 A. sleep(1000)  InterruptedException
 B. sleep(1000)  RuntimeException
 C. Thread.sleep(1000)  RuntimeException
 D. Thread.sleep(1000)  InterruptedException
 10.65. 已知有下列类的说明,则下列哪个语句是正确的? public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(    ); } }          (满分:3)
 A. t.f;
 B. this.n;
 C. Test.m;
 D. Test.f;
 11.选择正确的叙述.class Happy extends Frame {Happy(    ) {SetLayout(new GridLayout(2,2));Panel p1 = new Panel(    );add(p1);p1.add( new Button("One"));Panel p2 = new Panel(    );add(p2);p2.add( new Button("Two"));add( new Button("Three"));add( new Button("Four"));s          (满分:3)
 A. 当frame调整大小时,按钮Three和Four 的大小也将调整。
 B. 当frame调整大小时,所有按钮的大小都将调整。
 C. 当frame调整大小时,按钮Two和Four 的大小也将调整。
 D. 当frame调整大小时,按钮One和Two 的大小也将调整。
 12.请选择以下代码的正确的重载构造器。class Happy {Happy(    ) {}}          (满分:3)
 A. public void Happy(    ){}
 B. public Happy(int c){}
 C. protected Happy(    ){}
 D. void Happy(    ){}
 13.若有循环:int x=5,y=20;do{    y-=x;     x++;  }while(++x<--y);则循环体将被执行(    )。          (满分:3)
 A. 0次
 B. 1次
 C. 2次
 D. 3次
 14.给出如下代码:class Test{  private int m;  public static void fun(    ) {    // some code...  }}如何使成员变量m被函数fun(    )直接访问?          (满分:3)
 A. 将private int m 改为protected int m
 B. 将private int m 改为 public int m
 C. 将private int m 改为 static int m
 D. 将private int m 改为 int m
 15.设有下面的一个类定义:   class  AA {     static  void  Show(    ){ System.out.println("我喜欢Java!"); }   }   class  BB {  void  Show(    ){ System.out.println("我喜欢C++!"); } }若已经使用AA类创建对象a和BB类创建对象b,则下面哪一个方法调用是正确的:(    )          (满分:3)
 A. a.Show(    )b.Show(    )
 B. AA.Show(    )BB.Show(    )
 C. AA.Show(    )b.Show(    )
 D. a.Show(    )BB.Show(    )
 16.给定下面的类:  public class Example{   String str=new String(“good”);   char ch[]={'a','b','c'};  public static void main(String args[]){   Example ex=new Example(    );   ex.change(ex.str,ex.ch);   System.out.println(ex.str+”and”+ex.ch);   }   public void          (满分:3)
 A. good and abc
 B. good and gbc
 C. test ok and abc
 D. test ok and gbc
 17.下面语句返回的数据类型是什么?(short)10/10.2*2;          (满分:3)
 A. int
 B. double
 C. float
 D. short
 18.给出下列代码,如何使成员变量m 被方法fun(    )直接访问? class Test { private int m; public static void fun(    ) { ... } }          (满分:3)
 A. 将private int m 改为protected int m
 B. 将private int m 改为 public int m
 C. 将private int m 改为 static int m
 D. 将private int m 改为 int m
 19.下列哪个选项的java源文件代码片段是不正确的?          (满分:3)
 A. package testpackage; public class Test{ }
 B. import java.io.*; package testpackage; public class Test{ }
 C. import java.io.*; class Person{ } public class Test{ }
 D. import java.io.*; import java.awt.*; public class Test{ }
 20.Person, Student 和Teacher 都是类名。这些类有以下继承关系。Person|--------------------(    )Student    Teacher并且在Java源代码中有如下表达式:Person p = new Student(    );如下哪个语句是正确的?          (满分:3)
 A. 这条语句是合法的
 B. 这条语句是不合法的
 C. 编译时出错
 D. 编译正确但运行时出错
 二、多选题:
 1.在如下源代码文件Test.java中, 哪个是正确的类定义?          (满分:4)
 A. public class test {public int x = 0;public test(int x) {this.x = x;}}
 B. public class Test{public int x=0;public Test(int x) {this.x = x;}}
 C. public class Test extends T1, T2 {public int x = 0;public Test(int x) {this.x = x;}}
 D. public class
 2.你怎样从下面main(    )的调用中访问单词“kiss”?java lyrics a kiss is but a kiss          (满分:4)
 A. args[0]
 B. args[1]
 C. args[2]
 D. args[3]
 E. args[4]
 F. args[5]
 3.String s=”Example String”; 下面哪些语句是正确的?          (满分:4)
 A. s>>>=3;
 B. int i=s.length(    );
 C. s[3]=”x”;
 D. String shorts=s.trim(    );
 E. String t=”root”+s;
 4.选择所有有效的构造函数。class Happy {}}          (满分:4)
 A. public void Happy(    ){}
 B. public Happy(int c){}
 C. protected Happy(    ){}
 D. public int Happy(    ){}
 E. void Happy(    ){}
 5.针对下面的程序,那些表达式的值是true?  Class Aclass{   private long val;   public Aclass(long v){val=v;}   public static void main(String args[]){   Aclass x=new Aclass(10L);   Aclass y=new Aclass(10L);   Aclass z=y;   long a=10L;   int b=10;   }   }          (满分:4)
 A. a==b;
 B. a==x;
 C. y==z;
 D. x==y;
 E. a==10.0;
 6.已知如下定义:String s = "story";下面哪些表达式是合法的?          (满分:4)
 A. s += "books";
 B. char c = s[1];
 C. int len = s.length;
 D. String t = s.toLowerCase(    );
 7.下面的哪些程序片断可能导致错误。          (满分:4)
 A. String s="Gonewiththewind";String t="good";String k=s+t;
 B. String s="Gonewiththewind";String t;t=s[3]+"one";
 C. String s="Gonewiththewind";String standard=s.toUpperCase(    );
 D. String s="homedirectory";String t=s-"directory".
 8.已知如下代码:switch(m){case 0: System.out.println("Condition 0");case 1: System.out.println("Condition 1"); case 2: System.out.println("Condition 2");case 3: System.out.println("Condition 3");break;default: System.out.println("Other Condition"); }当m 的          (满分:4)
 A. 0
 B. 1
 C. 2
 D. 3
 E. 4
 F. 以上都不是
 9.下面代码执行后的输出是什么?outer: for(int i=0;i<3; i++)inner: for(int j=0;j<2;j++){if(j==1) continue outer;System.out.println(j+ “ and “+i);}          (满分:4)
 A. 0 and 0
 B. 0 and 1
 C. 0 and 2
 D. 1 and 0
 E. 1 and 1
 F. 1 and 2
 G. 2 and 0
 H. 2 and 1
 I. 2 and 2
 10.假定文件名是“Fred.java”,下面哪个是正确的类声明。          (满分:4)
 A. public class Fred{   public int x = 0;   public Fred(int x){   this.x=x;   }   }
 B. public class fred{   public int x = 0;   public Fred(int x){   this.x=x;   }   }
 C. public class Fred extends MyBaseClass{   public int x = 0; }
 更多免费学习资料请登录www.openhelp100.com
 
 
 | 
 |