Java基础练习题 附答案(5)

2018-12-11 22:49

}

以下那个说法正确? A. 编译时将产生错误;

B. 编译时正确,运行时将产生错误; C. 输出0; D. 输出null。

7)以下的程序的调试结果为? public class As{ int i = 10; int j; char z= 1; boolean b;

public static void main(String argv[]){ As a = new As(); a.amethod(); }

public void amethod(){ System.out.println(j);

System.out.println(b); } }

A.输出0 和false B. 输出0 和true C. 编译错误,b 未初始化 D. 编译错误, z 必须赋字符值 8)以下的程序的调试结果为? public class MyAr{

public static void main(String argv[]) { MyAr m = new MyAr(); m.amethod(); }

public void amethod(){ static int i;

System.out.println(i); }

}

A. 输出结果为 0 B. 运行出错 C. 输出结果为 null D. 编译错误

9) 以下程序的运行结果为? class ValHold{

public int i = 10; }

public class ObParm{

public static void main(String argv[]){ ObParm o = new ObParm(); o.amethod(); }

public void amethod(){ int i = 99;

ValHold v = new ValHold(); v.i=30; another(v,i);

System.out.print( v.i ); }

public void another(ValHold v, int i){ i=0; v.i = 20;

ValHold vh = new ValHold(); v = vh;

System.out.print(v.i); System.out.print(i); } }

A.10030 B. 20030 C. 209930 D. 10020

八、继承与多态

1)以下程序调试结果为: class Base{ Base(){

int i = 100; System.out.print (i); } }

public class Pri extends Base{ static int i = 200;

public static void main(String argv[]){ Pri p = new Pri(); System.out.print(i); } }

A.编译错误 B.200 C.100200 (2) 以下程序调试结果为: public class Test { int m=5;

public void some(int x) { m=x; }

public static void main(String args []) { new Demo().some(7); } }

class Demo extends Test { int m=8;

public void some(int x) { super.some(x); System.out.println(m); } }

A.5 B.8 C.7 D.无任何输出3) 试完成下述程序片段: public class Point() { int x,y;

public Point(int x,int y) { =x; =y;

D.100 E.编译错误 } ...... }

A. Point.x Point.y B.无解 C. x1 y1 D.this.x this.y (4)考虑如下类: 1. class Test(int i) { 2. void test(int i) {

3. System.out.println(\ 4. }

5. void test(String s) {

6. System.out.println(\ 7. } 8.

9. public static void main(String args[]) { 10. Test t=new Test(); 11. char ch=\ 12. t.test(ch); 13. } 14. }

以下哪条为真?

A.行 5 不能通过编译,方法不能被覆盖.

B.行 12 不能通过编译, 因为没有一个test()方法含字符参数. C.代码可以编译但在12行将出现异常. D.代码可以编译且产生如下输出: I am an int. E.代码可以编译且产生如下输出: I am a String. (5) 类Test1定义如下: 1.public class Test1{

2. public float aMethod(float a,float b){ } 3. 4.}

将以下哪种方法插入行3是不合法的。( ) A.public float aMethod(float a, float b,float c){ } B.public float aMethod(float c,float d){ } C.public int aMethod(int a, int b){ } D.private float aMethod(int a,int b,int c){ }

6)考虑如下代码: class Tree{}

class Pine extends Tree{} class Oak extends Tree{} public class Forest {

public static void main( String[] args ) { Tree tree = new Pine(); if( tree instanceof Pine ) System.out.println( \ if( tree instanceof Tree ) System.out.println( \ if( tree instanceof Oak ) System.out.println( \ else

System.out.println( \ } }

则输出结果中有哪些?

A.Pine B.Tree C.Forest D.Oops 7)以下程序的编译和运行结果为? abstract class Base{

abstract public void myfunc(); public void another(){

System.out.println(\ } }

public class Abs extends Base{

public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); }

public void myfunc(){

System.out.println(\ }

public void amethod(){

E.无输出


Java基础练习题 附答案(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:吉林大学计算机导论复习重点

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: