快捷导航
帮助中心知识拓展客服QQ 515224986
扫码加微信
16春学期《JAVA语言程序设计Ⅰ》在线作业3

一、单选题:
1.如果你试图编译下面的代码会发生什么事?Class MyString extends String{}          (满分:3)
    A. 代码编译成功
    B. 代码不能编译,因为没有定义一个main(    )方法
    C. 代码不能编译,因为String是abstract类型的
    D. 代码不能编译,因为String是final类型的
2.下面程序的输出结果是什么? class Foo{ static void change(String s){ s=s.replace('j','l'); } public static void main(String args[]){ String s="java"; change(s); System.out.println(s); } }          (满分:3)
    A. lava
    B. java
    C. 编译错误
    D. 运行时出现异常
3.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;
4.下列语句序列执行后,a的值是(    )。int a=13; a%=a/5;          (满分:3)
    A. 3
    B. 13
    C. 1
    D. 169
5.已知如下的命令执行java MyTest a b c请问哪个语句是正确的?          (满分:3)
    A. args[0] = "MyTest a b c"
    B. args[0] = "MyTest"
    C. args[0] = "a"
    D. args[1]= 'b'
6.下面程序的输出结果是什么?class C1{static int j=0;public void method(int a){j++;}}class Test extends C1{public int method(    ){return j++; } public void result(    ){ method(j); System.out.println(j+method(    )); } public static void main(String args[]){ new Te          (满分:3)
    A. 0
    B. 1
    C. 2
    D. 3
7.下列程序的功能是在监控台上每隔一秒钟显示一个字符串“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
8.Person, Student 和Teacher 都是类名。这些类有以下继承关系。Person|--------------------(    )Student    Teacher并且在Java源代码中有如下表达式:Person p = new Student(    );如下哪个语句是正确的?          (满分:3)
    A. 这条语句是合法的
    B. 这条语句是不合法的
    C. 编译时出错
    D. 编译正确但运行时出错
9.下列代码中,将引起一个编译错误的行是  1)public class Test{  2) int m,n;  3) public Test(    ) {}  4) public Test(int a) {m=a;}  5) public static void main(String args[]){  6) Test t1,t2;  7) int j,k;  8) j=0;k=0;  9) t1=new Test(    );  10) t2=new Test(j,k);  11) }  12          (满分:3)
    A. 第3行
    B. 第5行
    C. 第6行
    D. 第10行
10.给定下面的类:  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
11.设有下面两个类的定义:class  Person {                         long    id;     // 身份证号   String  name;   // 姓名    }                                             class  Student  extends  Person {           int  score;  // 入学总分           int  getScore(    ){      re          (满分:3)
    A. 包含关系
    B. 继承关系
    C. 关联关系
    D. 无关系,上述类定义有语法错误
12.下面的语句的作用是:(    )。    Vector  MyVector = new  Vector(100,50);          (满分:3)
    A. 创建一个数组类对象MyVector,有100个元素的空间,每个元素的初值为50。
    B. 创建一个向量类对象MyVector,有100个元素的空间,每个元素的初值为50。
    C. 创建一个数组类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。
    D. 创建一个向量类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。
13.给出下面的接口:interface A{        int method1(int i);        int method2(int j);}下面那个类实现了这个接口,并且不是抽象的?          (满分:3)
    A. class B implements A{        int method1(    ){}        int method2(    ){}}
    B. class B {        int method1(int i){}        int method2(int j){}}
    C. class B implements A{        int method1(int i){}        int method2(int j){}}
    D. class B extends A{        int method1(int i){}        int method2(int j){}}
14.选择正确的叙述.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 的大小也将调整。
15.下面的代码段中,执行之后i 和j 的值是什么?int i = 1;int j;j = i++;          (满分:3)
    A. 1
     1
    B. 1
     2
    C. 2
     1
    D. 2
     2
16.设有下面的一个类定义:   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(    )
17.下列程序段执行后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
18.有下面的类:  public class Example{   static int x[]=new int[15];   public static void main(String args[]){   System.out.println(x[5]);   }   } 下面的那些说法是正确的。          (满分:3)
    A. 编译时出错
    B. 运行时出错
    C. 输出0
    D. 输出null
19.给出下列代码,如何使成员变量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
20.下面程序的输出结果是什么?public static void main(String args[]){int a=10;int b=20;if(a=b)System.out.println("Not Equal");elseSystem.out.println("Equal");}          (满分:3)
    A. Equal
    B. Not Equal
    C. 编译错误
    D. 运行时将抛出异常
二、多选题:
1.选择所有有效的构造函数。class Happy {}}          (满分:4)
    A. public void Happy(    ){}
    B. public Happy(int c){}
    C. protected Happy(    ){}
    D. public int Happy(    ){}
    E. void Happy(    ){}
2.假定文件名是“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; }
3.已知如下代码: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. 以上都不是
4.在如下源代码文件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
5.已知如下代码:public class Test{public static void main(String arg[]){int i = 5;do {System.out.println(i);} while(--i>5)System.out.println("finished");}}执行后的输出结果包括什么?          (满分:4)
    A. 5
    B. 4
    C. 6
    D. finished
    E. 什么都不输出
6.已知如下类说明: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(    );// 程序代码…} }如下哪个使用是正确的?          (满分:4)
    A. t.f
    B. this.n
    C. Test.m
    D. Test.n
7.下面代码执行后的输出是什么?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
8.已知如下类定义:class Base {public Base(    ){ //... }public Base( int m ){ //... }protected void fun( int n ){ //... }}public class Child extends Base{// member methods}如下哪句可以正确地加入子类中?          (满分:4)
    A. private void fun( int n ){ //...}
    B. void fun( int n ){ //... }
    C. protected void fun( int n ) { //... }
    D. public void fun( int n ) { //... }
9.你怎样从下面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]
10.下面的哪些程序片断可能导致错误。          (满分: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".

奥鹏易百网www.openhelp100.com专业提供网络教育各高校作业资源。

共 0 个关于本帖的回复 最后回复于 2016-3-30 21:33

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

精彩推荐

    明星用户

    QQ|Archiver|手机版|小黑屋|www.openhelp100.com ( 冀ICP备19026749号-1 )

    GMT+8, 2024-4-27 10:09