编写一个方阵类.doc_第1页
编写一个方阵类.doc_第2页
编写一个方阵类.doc_第3页
编写一个方阵类.doc_第4页
编写一个方阵类.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

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

文档简介

练习题编写一个方阵类,其中封装有对方阵进行操作的方法,包括:l 两个n阶方阵的加;l 两个n阶方阵的减;l 求方阵的转置矩阵;l toString()方法按行、列描述矩阵(其中包含n字符)。试分别就3阶方阵和4阶方阵的数据验证类设计。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编译错误 B200 C100200 D100 答:C(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); A5 B8 C7 D无任何输出 E编译错误 答:B3) 试完成下述程序片段:public class Point() int x,y; public Point(int x,int y) =x; =y; .A Point.x Point.y B无解 C x1 y1 Dthis.x this.y答:D(4)考虑如下类:1. class Test2. void test(int i) 3. System.out.println(I am an int.);4. 5. void test(String s) 6. System.out.println(I am a string.);7. 8.9. public static void main(String args) 10. Test t=new Test();11. String ch=y;12. t.test(ch);13. 14. 以下哪条为真?A行 5 不能通过编译,方法不能被覆盖.B行 12 不能通过编译, 因为没有一个test()方法含字符参数.C代码可以编译但在12行将出现异常.D代码可以编译且产生如下输出: I am an int.E代码可以编译且产生如下输出: I am a String.答:E(5) 类Test1定义如下:1public class Test12 public float aMethod(float a,float b) 3 4 将以下哪种方法插入行3是不合法的。( )Apublic float aMethod(float a, float b,float c) Bpublic float aMethod(float c,float d) Cpublic int aMethod(int a, int b) Dprivate float aMethod(int a,int b,int c) 答:B6)考虑如下代码:class Treeclass Pine extends Treeclass Oak extends Treepublic class Forest public static void main( String args ) Tree tree = new Pine(); if( tree instanceof Pine ) System.out.println( Pine ); if( tree instanceof Tree ) System.out.println( Tree ); if( tree instanceof Oak ) System.out.println( Oak ); else System.out.println( Oops ); 则输出结果中有哪些?APine BTree CForest DOops E无输出答:ABD7)以下程序的编译和运行结果为?abstract class Base abstract public void myfunc(); public void another() System.out.println(Another method); public class Abs extends Base public static void main(String argv) Abs a = new Abs(); a.amethod(); public void myfunc() System.out.println(My Func); public void amethod() myfunc(); A输出结果为 My FuncB编译指示 Base 类中无抽象方法C编译通过,但运行时指示Base 类中无抽象方法D编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。答:A8) 以下程序的调试结果为?class Basepublic final void amethod() System.out.println(amethod); public class Fin extends Base public static void main(String argv) Base b = new Base(); b.amethod(); A编译指示带有final 方法的类自己必须定义为finalB编译指示不能继承含有final 方法的类C运行错误,原因是Base类没有定义为final类D运行输出 amethod答:D9) 在同一目录编译和运行以下两文件结果如何?/文件 P1.javapackage MyPackage;class P1 void afancymethod() System.out.println(What a fancy method); /文件 P2.javapublic class P2 extends P1 public static void main(String argv) P2 p2 = new P2(); p2.afancymethod(); A两个均通过编译,P2运行时输出 What a fancy methodB没一个通过编译C两个均通过编译,但P2运行时出错DP1 通过编译,但P2出现编译错误答:D10)以下程序的调试结果为?public class Outerpublic String name = Outer;public static void main(String argv) Inner i = new Inner(); i.showName();private class Inner String name =new String(Inner); void showName() System.out.println(name); A输出结果 OuterB输出结果 InnerC编译错误,因Inner类定义为私有访问D在创建Inner类实例的行出现编译错误答:D11) 设有如下代码:class Basepublic class MyCast extends Base static boolean b1=false; static int i = -1; static double d = 10.1; public static void main(String argv) MyCast m = new MyCast(); Base b = new Base(); /Here 则在 /Here处插入哪个代码将不出现编译和运行错误。Ab=m; Bm=b; Cd =i; Db1 =i;答:AC12) 设有如下代码:interface IFaceclass CFace implements IFaceclass Basepublic class ObRef extends Base public static void main(String argv) ObRef obj = new ObRef(); Base b = new Base(); Object obj1 = new Object(); IFace obj2 = new CFace();/Here 则在 /Here处插入哪个代码将不出现编译和运行错误。Aobj1=obj2; Bb=obj; Cobj=b; Dobj1=b;答:ABD13) 设有类定义如下:class Basepublic Base(int i)public class MyOver extends Basepublic static void main(String arg) MyOver m = new MyOver(10);MyOver(int i) super(i);MyOver(String s, int i) this(i); /Here以下哪条语句可以安排在/Here处 ?AMyOver m = new MyOver();Bsuper();Cthis(Hello,10);DBase b = new Base(10);答:D14) 设有类定义如下:class InOutString s= new String(Between);public void amethod(final int iArgs) int iam

温馨提示

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

评论

0/150

提交评论