类和对象课堂练习.ppt_第1页
类和对象课堂练习.ppt_第2页
类和对象课堂练习.ppt_第3页
类和对象课堂练习.ppt_第4页
类和对象课堂练习.ppt_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Java面向对象程序设计,课堂练习,2,习题1,下列叙述中,错误的是_。 A 、父类对象不能替代子类对象 B、子类对象能够替代父类对象 C、子类继承父类 D、父类包含子类,D,3,习题2,下列代码中,将引起一个编译错误的行是_。 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: A、第3行 B、第5行 C、第6行 D、第10行,D,4,习题3,阅读下列代码. 正确的说法是_。 public class Person int arr =new int10; public static void main(String args) System.out.println(arr1); A、编译时将产生错误 B、编译时正确,运行时将产生错误 C、输出为0 D、输出为空,A,5,习题4,public class Parent public int addValue( int a, int b) int s; s = a+b; return s; class Child extends Parent /在此加入某个方法 下列选项中,_方法可以正确加入类Child中且不会重写父类的方法。 A、int addValue( int a, int b )/ do something. B、public void addValue ( )/ do something. C、public int addValue( int a, int b ) throws MyException /do something. D、public float addValue ( int a ,int b, float b=1.0f )/ do something.,B,答案:,6,习题5,欲构造ArrayList类的一个实例,此类实现了List接口,下列_是正确的。 A、ArrayList myList=new Object( ); B、List myList=new ArrayList( ); C、ArrayList myList=new List( ); D、List myList=new List( );,B,解析:不能直接创建接口的实例,只能通过实现接口的类来完成,7,习题6,在某个类中定义一个方法: void GetSort(int x),以下关于能否作为这个方法的重载中,错误的是_ void GetSort(float x)x*=x; int GetSort(double y)return (int)(s*y); double GetSort(int x,int y)return x+y; 以上都不是重载,D,8,习题7,下面在命令行运行Java应用程序A:java A the first snow, the first snow came. 怎样才能在main(String a )方法中访问单词“first”?_ A a0 B a2 C a4 D a5,C,9,习题8,下列哪个声明语句是正确的? A.abstract final class Hi B.abstract private move() C.protected private number; D.public abstract class Car 答案:,D,10,习题9,给出如下代码: class Test private int m; public static void fun() / some code. 如何使成员变量m 被方法fun()直接访问? 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,答案: C,11,习题10,下面哪几个方法是public void example().的重载方法? A. public void example( int m). B. public int example(). C. public void example2(). D. public int example ( int m, float f).,答案: A,D,12,习题11,给出下面的代码段: public class Base int w, x, y ,z; public Base(int a,int b) x=a; y=b; public Base(int a, int b, int c, int d) / assignment x=a, y=b w=d; z=c; 在代码说明/ assignment x=a, y=b处写入如下哪几个代码是正确的? A、Base(a,b); B、x=a, y=b; C、x=a; y=b; D、this(a,b);,答案: C,D,13,习题12,Java中main()方法的返回值是什么类型? A、 String B、int C、char D、void 答案:,D,14,习题13,下面哪个是main()方法的合法参数? A、char args B、char args C、String arg D、String args 答案:,C,15,习题14,已知如下的命令执行 java MyTest a b c 请问哪个表达式的值为true? A、 args0 = “MyTest a b c“ B、args0 = “MyTest“ C、args0 = “a“ D、args1= b 答案:,C,16,习题15,已知如下代码: public class Test long a = new long10; public static void main ( String arg ) Test t=new Test(); System.out.println (t.a10 ); 请问哪个结论是正确的? A、执行结果为 null. B、执行结果为 0. C、编译出错. D、运行出错. 答案:,D,17,习题16,已知如下类定义: 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(); / 此处填入代码 下列选项中正确的是 ? A、 t.f B、this.n C、Test.m D、Test.n 答案:,A, D,18,习题17,已知如下代码: 1: class Example 2: String str; 3: public Example() 4: str= “example“; 5: 6: public Example(String s) 7: str=s; 8: 9: 10: class Demo extends Example 11: 12: public class Test 13: public void f () 14: Example ex = new Example(“Good“); 15 Demo d = new Demo(“Good“); 16: 哪句语句会导致错误? A、 line 3 B、line 6 C、line 10 D、line 14 E、line 15,答案:E,19,习题18,源代码文件Test.java中, 哪些是正确的? A、public class Test public int x=0; public Test(int x) this.x = x; C、 public class Test extends T1 implements I1, I2 public int x=0; public Test(int x) this.x = x; ,答案:A,C,B、public class Test extends T1, T2 public int x = 0; public Test (int x) this.x = x; D、protected class Test extends T2 public int x=0; public Tes

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论