1609第一次月考详细解析.doc_第1页
1609第一次月考详细解析.doc_第2页
1609第一次月考详细解析.doc_第3页
1609第一次月考详细解析.doc_第4页
1609第一次月考详细解析.doc_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

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

文档简介

1.(单选题)下列数组声明语句中,错误的是:()。 A.int arr = new int; B.int arr = new int;/缺少数组长度 C.int arr = ; D.int arr = new int2;正确答案:B2.(单选)class Card下列不属于Card类构造方法的是:() A.Card() B.public Card() C.public void Card()/构造方法没有返回值,但也不能写void D.private Card()正确答案:C3.(单选)下面不属于Java语言特点的是: A.平台无关 B.面向对象 C.支持指针类型/不是java的特点,是c语言的 D.垃圾回收机制正确答案:C4.(单选)下列选项中的类,能正确实现java.lang.Runnable接口和java.lang.Clonable接口的是()。 A.public class Session implements Runnable, Clonable public void run(); /实现接口,要重写接口的抽象方法public Object clone(); B.public class Session implements Runnable, implements Clonable /写一个implements即可 public void run() / do something */ public Object clone() / make a copy */ C.public class Session implements Runnable, Clonable public void run() / do something */ public Object clone() /* make a copy */ D.public class Session extends Runnable, Clonable /接口不是用来继承的 public void run() ; public Object clone(); 正确答案:C5.(单选)下列属于不合法Java标识符的是()。/ java 标识符命名规范: 字母、数字、$、_(下划线),不可用数字开头,不能是java 的关键字 A._mem B.12a/不能以数字开头 C.M12 D.$12正确答案:B6.(单选)下列Java标识符,错误的是() A._sys_varl B.$change C.User_name D.1_file/不能以数字开头正确答案:D7.(单选)Java程序的执行过程中用到一套JDK工具,其中javac.exe是指()。 A.Java语言编译器 B.Java字节码解释器 C.Java文档生成器 D.Java类分解器正确答案:A8.(单选)运行下列代码: int oneArr = 2, 11, 26, 27, 37, 44, 48, 60 ; int twoArr = 19, 35, 49, 55, 58, 75, 83, 84, 91, 93 ; int threeArr = new intoneArr.length + twoArr.length; int p = 0, q = 0; while (p oneArr.length & q twoArr.length) threeArrp + q = oneArrp twoArrq ? oneArrp+ : twoArrq+; if (p oneArr.length) System.arraycopy(oneArr, p, threeArr, p + q, oneArr.length - p); else if (q 1;/需要强转byte b=(byte)(b11); D.byte b1 = 10; byte b=+b1;正确答案:D12.(单选)类Super及Sub定义如下: public class Super private void f() System.out.println(Super.f(); public void g() f(); public void k() f(); public class Sub extends Super private void f() System.out.println(Sub.f(); public void k() f(); 运行下列语句: Super obj = new Sub();/创建了一个obj的引用变量指向Sub对象,类型为Superobj.g();/能点出来什么看类型,所以这时调的g方法应该是访问Super的g()方法,g方法里调f()方法,父类的f()方法为private为不可重写。虽然子类中看上去重写了,其实是两个无关f()方法,只是方法名而已。在多态调用的时候,只会直接找父类的f()方法.所以调用f()方法时,实际是调用父类的private。输出:Super.f() obj.k(); /调k()方法,子类重写后的版本,它为一个公共方法,该公共方法再调用本类的私有方法.输出:Sub.f() 输出的结果是:()。 A.Sub.f() Sub.f() B.Sub.f() Super.f() C.Super.f() Sub.f() D.Super.f() Super.f()正确答案:C13.(单选)关于下列代码说法正确的是: class ClassA public int numberOfinstances; protected ClassA(int numberOfinstances) this.numberOfinstances = numberOfinstances; public class ExtendedA extends ClassA private ExtendedA(int numberOfinstances) super(numberOfinstances); public static void main(String args) ExtendedA ext = new ExtendedA(420); /new对象,走进子类构造方法,执行代码前先调用父类的有参构造方法System.out.print(ext.numberOfinstances); A.运行后,输出420 B.运行时抛出异常 C.编译错误,所有的构造器必须是public的 D.编译错误,构造器不能是private的正确答案:A/子类(Sub class)可以继承父类(Super class)的成员变量及成员方法。届时,子类将具有父类的成员注意补充:java构造方法的修饰符:public,protected,默认,private四种都可以使用public修饰构造方法,那么所有的类都可以实例化这个类。使用private修饰构造方法,那么所有的类都不可以实例化使用这个类。14.(单选)关于下列代码说法正确的是: public class A private int counter = 0; public static int getInstanceCount() return counter; public A() counter+; public static void main(String args) A a1 = new A(); A a2 = new A(); A a3 = new A(); System.out.println(A.getInstanceCount(); A.该类编译失败 B.输出:1 C.输出:3 D.输出:0正确答案:A/在static方法中无法返回非static的变量由于static在调用时没有具体的对象,因此在static方法中不能对非static成员(对象成员)进行访问。15.(单选)下面for语句,存在编译错误的是()。 A.for( ; ; )/相当于while(true),死循环 B.for(int i=0; i 100;i+) C.for(int i = 0, j=0; ;i+,j+)/相当于while(true),死循环 D.for(int i = 0; i 10)/缺循环变量的变化正确答案:D16.(单选)请看下列代码: interface Foo int bar(); public class Sprite public int fubar(Foo foo) return foo.bar(); public void testFoo() fubar( ); 使类Sprite编译通过,在处应填入的代码是: A.Foo public int bar() return 1; B.new Foo public int bar() return 1; C.new Foo() public int bar()return 1; D.new class Foo public int bar() return 1; 正确答案:C/ 接口无法实例化:fubar方法中需要传入一个Foo类型的参数,但是Foo只是一个接口,无法直接实例化对象,因此在这里我们选择了匿名内部类进行实例化17.(单选)请看下列代码: public class Plant private String name; public Plant(String name) = name; /Plant中的有参的构造方法 public String getName() return name; class Tree extends Plant public void growFruit() public void dropLeaves() 下列说法正确的是:A. 在Tree类中添加代码:public Tree() Plant(); ,编译将通过/子类构造方法中调用父类的构造方法,写法是:super();不写的话系统会默认有 B.在Plant类中添加代码:public Plant() Tree(); ,编译将通过 C.在Plant类中添加代码:public Plant() this(”fern”); ,编译将通/无参构造方法中调用有参的构造方法,可以。格子类的时候,有类似的例子 D.在Plant类中添加代码:public Plant() Plant(”fern”); ,编译将通过正确答案:C18.(单选)请看下列代码编译和运行的结果是()。 interface DeclareStuff public static final int EASY = 3; void doStuff(int t); public class TestDeclare implements DeclareStuff public static void main(String args) int x = 5; new TestDeclare().doStuff(+x); /调用方法,把+x(为6)传给了形参s,这时s为6s = 6 + 3 + 7 void doStuff(int s) /编译错误,方法缺public 修饰,接口的方法默认都是由public abstract 修饰的 s += EASY + +s; /等同于s = s + EASY + (+s)/用debug调试,非常容易看到结果的变化System.out.println(s= + s); A.s=14 B.s=16 C.s=10 D.编译失败正确答案:D/如果没有编译错误,能输出s=1619.(单选)下列关于IDE开发环境Eclipse,说法错误的是:()。 A.Eclipse可以通过插件(plugin)的方式扩展其功能。 B.Eclipse联盟是由IBM公司捐资组建的。 C.Eclipse使用了SWT图形界面技术。 D.Eclipse的运行不需要有JRE的支持。正确答案:D/这题都要讲解的话,是在侮辱你的智商20.(单选)下列代码的输出结果是: public class Blip protected int blipvert(int x) return 0; class Vert extends Blip 在处填入选项中的代码,使Vert类没有编译错误的是()。/继承,可以对方法进行重写,两同两小一大原则: A.public int blipvert(int x) return 0; B.private int blipvert(int x) return 0; /权限要比父类大或相等 C.private void blipvert(int x) return 0; /权限和返回类型都错了 D.protected long blipvert(int x) return 0; /如果返回值是基本类型要保持一致正确答案:A21.(单选)下列表达式中,可以得到精确结果的是()。 A.double d1 = 3.0 - 2.6; B.double d4 = 2.5 * 1.5; C.double d2 = 30/300; D.double d3 = 1/2 + 0.5;/1/2是取整,为0,没法得到0.5正确答案:B22.(单选)下列代码的输出结果是()。 public static void main(String args) int one=new int4,6,8; int two=new int1,3,5,7,9; System.arraycopy(one, 1, two, 2, 2); System.out.println(Arrays.toString(two); A.1, 3, 7, 4, 6 B.1, 3, 5, 7, 8 C.1, 3, 5, 6, 9 D.1, 3, 6, 8, 9正确答案:Dsrc:源数组srcPos:源数组中的起始位置dest:目标数组destPos: 目标数组中的起始位置length:要复制的数组元素的数量arraycopy(Object src, int srcPos,Object dest, int destPos, int length)23.(单选)下列数组声明语句中,错误的是:()。 A.int arr = new int8; B.int arr = new int8; C.int arr = ; D.int arr = new int;正确答案:B24.(单选)下列代码编译和运行的结果是: public static void main(String args) String elements = for, tea, too ; String first = (elements.length 0) ? elements0 : null;true System.out.println(first); A.编译出错 B.输出:tea C.输出:for D.输出:null正确答案:C25.(单选)运行下面的程序: int a = 100; int b = 200; a = a + b; /a = 100+200 = 300;b = a - b; /b = 300-200 = 100;a = a - b; /a = 300 100 = 200;System.out.println(a= + a + , b= + b); 输出的结果是:()。 A.a=100, b=300 B.a=100, b=200 C.a=200, b=100 D.a=300, b=200正确答案:C26.(单选)下列关于JVM说法,错误的是()。 A.JVM通过专门的线程实现内存的回收。 B.使用java命令时,可以通过参数来设置分配JVM的内存大小。 C.JRE包括JVM及Java核心类库。 D.目前主流版本JVM通过纯解释的方式运行Java字节码。正确答案:D JVM先通过javac进行编译,再将编译后的字节码文件通过java指令进行解释运行,如果纯解释的话根本无法识别源码27.(单选)请看下列代码: interface Data public void load(); abstract class Info public abstract void load(); 下列选项中,能正确使用Data接口和Info类的是()。 A.public class Employee extends Info implements Data public void load() /*do something*/ B.public class Employee implements Info extends Data public void load() /*do something*/ /要先继承后实现 C.public class Employee implements Info extends Data public void Data.load() /*d something */ public void load() /*do something */ D.public class Employee extends Info implements Data public void load() /*do something */ public void Info.load() /*do something*/ 正确答案:A先继承后实现,排除BC,D中Info.load()错误,静态方法才可以通过类名点方法注意:接口中的load和Info中的load的签名完全一致,同时没有父子继承关系,所以load方法既不构成重载,也不构成重写。28.(单选)类A,B的定义如下: class A private int a = 100; A() System.out.print(A(); System.out.println(a); class B extends A private int a = 200; B() System.out.print(B(); System.out.println(a); 运行下面的代码: new B(); 实例化B类对象,程序调用B类无参构造器,执行代码前先隐式调用父类无参构造输出的结果是:()。 A.A() 100 B() 200 B.A() 200 B() 200 C.B() 200 A() 100 D.B() 200 A() 200正确答案:A29.(单选)如下方法声明中,错误的是()。 A.public void say() System.out.print(“Hi”); B.public void say() System.out.print(“Hi”); return; C.public int say() System.out.print(“Hi”); return; 缺返回值 D.public int say() System.out.print(“Hi”); return 0; 正确答案:C30.(单选)下列代码编译和运行的结果是()。 public class A public void start() System.out.println(TestA); public class B extends A public void start() System.out.println(TestB); public static void main(String args) (A) new B().start(); (父类)new 子类(),实例化B类对象然后被强转为父类类型,再调用start的方法,但是当子类重写了父类的方法后,该重写方法被调用时(无论是通过子类的引用调用还是通过父类的引用调用),运行的都是子类重写后的版本 A.输出:TestA B.输出:TestB C.输出:TestA TestB D.编译错误正确答案:B31.(单选)下列代码的运行结果是: public class GoTest public static void main(String args) Sente a = new Sente();a.go();Goban b = new Goban(); b.go();调子类重写的版本Stone c = new Stone();c.go(); 继承父类的方法,没有重写,调父类中的go方法 爷爷 class Sente implements Go 实现了Go接口,重写了go方法public void go() System.out.println(go in Sente); 父亲 class Goban extends Sente public void go() System.out.println(go in Goban); 儿子 class Stone extends Goban implements Go interface Go public void go(); A.go in Goban go in Sente go in Sente B.go in Sente go in Sente go in Goban C.go in Sente go in Goban go in Goban D.go in Goban go in Goban go in Sente正确答案:C32.(单选)程序的执行结果是()。 public class Test int x; public static void main(String args) Test t = new Test(); t.x=5; change(t); System.out.println(t.x); public static void change(Test t) t.x=3; A.5 B.3 C.0 D.4正确答案:B x为成员变量,作用域为整个Test类33.(单选)分析如下语句,说法错误的是()。 A.break可用于跳出循环,当多层嵌套时,只用于跳出一层循环 B.break即可以出现在循环语句中也可以出现在switch语句中 C.continue可以用于跳出循环 D.continue不能出现在switch语句中正确答案:Cbreak”语句用来结束循环,即不再执行后边的所有循环。“continue”语句用来结束当前循环,并进入下一次循环,即仅仅这一次循环结束了,不是所有循环结束了,后边的循环依旧进行。34.(单选)请看下列代码编译和运行的结果是: package packagea; public class Message String getText() return text; package packageb; public class XMLMessage extends packagea.Message String getText() return text; public static void main(String args) System.out.println(new XMLMessage().getText(); 直接new对象了 A.text B.text C.抛出运行时异常 D.代码public class XMLMessage extends packagea.Message行,编译错误正确答案:B这题中XMLMessage继承Message是一个幌子,在println方法中我们new出来得是XMLMessage对象,直接调用XMLMessage的getText方法35.(单选)程序执行的结果是()。 public class Test String name=Tom; public Test(String name) =name; /没有this public static void main(String args) Test t = new Test(Jack); System.out.println(); /直接访问成员变量 A.null B.Tom C.Jack D. 正确答案:B36.(单选)请看下列代码的输出结果是: public class Bootchy int bootch; String snootch; public Bootchy() 构造方法的重载this(snootchy); 第一先进来这里System.out.print(first );最后输出 public Bootchy(String snootch) this(420, snootchy);第二进这里 System.out.print(second );其次输出 public Bootchy(int bootch, String snootch) this.bootch = bootch; 第三进这里this.snootch = snootch; System.out.print(third ); 首先输出 public static void main(String args) Bootchy b = new Bootchy(); System.out.print(b.snootch + + b.bootch); A.first second third snootchy 420 B.third second first snootchy 420 C.third first second snootchy 420 D.first second first third snootchy 420正确答案:B37.(单选)下列代码的输出结果是:()。 public class StaticFoo int num; static int x; public static void main(String args) StaticFoo foo1 = new StaticFoo (); foo1.num+; foo1.x+; StaticFoo foo2 = new StaticFoo (); foo2.num+; foo2.x+; StaticFoo foo3 = new StaticFoo (); foo3.num+; foo3.x+; StaticFoo.x+; System.out.print(foo3.num+,); System.out.println(foo3.x); A.3,3 B.1,3 C.3,4 D.1,4正确答案:D静态变量,也就是在变量前加了static 的变量;也叫类变量,只有一份,存在方法区实例变量也叫对象变量,即没加static 的变量;区别在于:静态变量和实例变量的区别在于:静态变量是所有对象共有,其中一个对象将它值改变,其他对象得到的就是改变后的结果;而实例变量则属对象私有,某一个对象将其值改变,不影响其他对象38.(单选)请看下列程序的输出结果是: public class Item private String desc; public String getDescription() return desc; public void setDescription(String d) desc = d; public static void modifyDesc(Item item, String desc) item = new Item(); item.setDescription(desc); public static void main(String args) Item it = new Item();it.setDescription(Gobstopper); /desc = GobstopperItem it2 = new Item(); it2.setDescription(Fizzylifting);/desc = FizzyliftingmodifyDesc(it, Scrumdiddlyumptious); /desc = ScrumdiddlyumptiousSystem.out.println(it.getDescription(); System.out.println(it2.getDescription();/set方法是为对象中的属性赋值;get方法是从对象中获取属性值A.Scrumdiddlyumptious Scrumdiddlyumptious B.Scrumdiddlyumptious Fizzylifltng C.Gobstopper Scrumdiddlyumptious D.Gobstopper Fizzylifting正确答案:Ditem=new Item();之后更改的变量内存地址不会对外部那个item的地址进行修改,在modifyDesc()自然就不会更改外部那个变量的值。传递对象一般是引用,即地址,如果在里面重新new了后的变量地址是相当另外一个变量不会影响外面那个变量地址,这样那个内存地址的值就不会被改变了,外面变量地址没改变,指向的仍是开始所指向的对象39.(单选)下面的代码用于对数组arr实现冒泡排序: for (int i = 0; i i; j-) if (arrj 0; j-) if (arrj arrj - 1) int temp = arrj; arrj = arrj - 1; arrj - 1 = temp; isSwap = true; C.for (int j = i + 1; j arr.length; j+) if (arrj arrj - 1) int temp = arrj; arrj = arrj - 1; arrj - 1 = temp; isSwap = true; D.for (int j = i; j arr.length; j+) if (arrj arrj - 1) int temp = arrj; arrj = arrj - 1; arrj - 1 = temp; isSwap = true; 正确答案:A太恐怖了,这代码,自己放eclipse运行一下吧40.(单选)请看下列代码: class Payload private int weight; public Payload(int wt) weight = wt; public Payload() public void setWeight(int w) weight = w; public String toString() return Integer.toString(weight); public class TestPayload static void changePayload(Payload p) public static void main(String args) Payload p = new Payload(); p.setWeight(1024);weight = 1024 changePayload(p);把引用的地址传进去,然后再通过调用set的方法改变这个地址指向的对象的内容,把weight值由1024改为420 System.out.println(The value of p is + p); /这里直接输出p指向的对象,会自动调用toString的方法假设运行后输出“The value of p is 420”,那么处应填入代码是: A.p.setWeight(420); B.Payload.setWeight(420); C.p = new Payload(420); D.p = new Payload(); p.setWeight(420);正确答案:A41.(单选)下列代码的输出结果是()。 abstract class Vehicle public int speed() return 0; class Car extends Vehicle public int speed() return 60; class RaceCar extends Car public int speed() return 150; public class TestCar public static void main(String args) RaceCar racer = new RaceCar(); Car car = new RaceCar(); Vehicle vehicle = new RaceCar(); System.out.println(racer.speed() + , + car.speed() + , + vehicle.speed(); A.0, 0, 0 B.150, 60, 0 C.150, 150, 150 D.抛出运行时异常正确答案:C当子类重写了父类的方法后,该重写方法被调用时(无论是通过子类的引用调用还是通过父类的引用调用),运行的都是子类重写后的版本42.(单选)题目: 下列代码的输出结果是: ()。 public class A public void info() System.out.println(A info); public class B extends A public void info() System.out.println(B info); public static void main(String args) B b=new B(); A a=b;a. info(); A.B info A info B.A info B info C.A info D.B info正确答案:D当子类重写了父类的方法后,该重写方法被调用时(无论是通过子类的引用调用还是通过父类的引用调用),运行的都是子类重写后的版本43.(单选)请看下列代码: class ClassA class ClassB extends ClassA class ClassC extends ClassA public class Test public static void main(String args) ClassA p0 = new ClassA(); ClassB p1 = new ClassB(); ClassC p2 = new ClassC(); ClassA p3 = new ClassB();ClassA p4 = new ClassC(); 可以在处,填入的代码正确的是() A.p0 = p1

温馨提示

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

评论

0/150

提交评论