java练习题_第1页
java练习题_第2页
java练习题_第3页
java练习题_第4页
java练习题_第5页
已阅读5页,还剩33页未读 继续免费阅读

下载本文档

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

文档简介

1.Java 语言是 1995 年发布的,发布该语言的公司是: A.Oracle B.Borland C.Microsoft D.Sun 2.编译和运行以下代码的结果为: public class Hello public static void main(String s) System.out.println(“Hello“); A.编译错误 B.运行输出 “Hello“ C.编译无错,但运行时指示没有定义构造方法 D.编译无错,但运行时指示没有正确定义 main 方法 3.关于下列代码说法正确的是: public static void main(String args) int first = 100; System.out.println(first); System.out.println(second); first = 123.456; A.编译正确 B.代码 System.out.println(first);行,编译出错 C.代码 System.out.println(second);行,编译无错 D.代码 first = 123.456;行,编译出错 4.下列代码出错的行是: 1) public void modify() 2) int i, j, k; 3) i = 100; 4) while ( i 0 ) 5) j = i * 2; 6) System.out.println (“ The value of j is “ + j ); 7) k = k + 1; 8) i-; 9) 10) A.4B.6C.7D.8 5.下列程序编译或运行的结果是: public static void main(String args) int num = 100; for(int i=0;i4) ? 99.9 :9); A.输出结果为:valueis99.99 B.输出结果为:valueis9 C.输出结果为:valueis9.0 D.编译错误 15.下列代码的输出结果是: int a=10; System.out.println(a2); A.2 B.4 C.40 D.42 16.0010101 语句的执行结果为: A.1101010 B.0010101 C.11111111 D.10001000 17.下面代码的输出结果是 public class Main public static void main(String args) int n1 = 1; int n2 = 2; n1 = n1 + n2; n2 = n1 - n2; n1 = n1 - n2; System.out.println(n1 + “,“ + n2); A.1,2 B.2,1 C.1,3 D.3,2 18.Java 语言中字符串“学 Java”所占的内存空间是: A.6 个字节 B.7 个字节 C.10 个字节 D.11 个字节 19.下列代码段的输出结果是: public static void main(String args) int x = 5; boolean b1 = true; boolean b2 = false; if (x = 4) System.out.print(“2 “); if (b2 = true) A.2 B.3 C.1 2 D.2 3 20.请看看列代码: public void testIfA() if (testIfB(“True“) System.out.println(“True“); else System.out.println(“Not true“); public Boolean testIfB(String str) return Boolean.valueOf(str); 调用 testIfA 方法,程序的结果是: A.输出 Not true B.输出 True C. if (testIfB(“True“) 行,编译错误 D. return Boolean.valueOf(str); 行,编译错误 21.下列语句序列执行后,k 的值是。 inti=10, j=18, k=30; switch( j - i ) case8 :k+; case9 :k+=2; case10:k+=3; default :k/=j; A.31 B.32 C.2 D.33 22. 以下由 for 语句构成的循环执行的次数是: for ( inti = 0; true ; i+) ; A.执行 3 次 B.无限次 C.执行 1 次 D.一次也不执行 23.观察以下程序段 : int i=1,j=10; do if(i+-j) continue; while(i 6) break; System.out.println(i); A.输出 6 B.输出 7 C.输出 10 D.编译错误 25.下面程序的输出结果是: public static void main(String args) int d = 325; int sum = 0; while (d 0) int n = d % 10; sum += n; d /= 10; System.out.println(sum); A.10 B.12 C.5 D.32 26.关于 while 和 dowhile 循环,下列说法正确的是 A.两种循环除了格式不同外,功能完全相同 B.与 dowhile 语句不同的是,while 语句的循环至少执行一次 C.do-while 语句首先计算终止条件,当条件满足时,才去执行循环体中的语句 D.与 while 语句不同的是,do-while 语句的循环至少执行一次 27.执行完以下代码 int x = newint25;后,下列各项正确的是: A.x24为 0 B.x24未定义 C.x25为 0 D.x0为空 28.下列代码编译和运行的结果是: public static void main(String args) int x = 1, 2, 3, 4, 5 ; int y = x; System.out.println(y2); A.输出 2 B.输出 3 C.输出 4 D.编译错误 29.下面代码的输出结果是 public class Main public static void main(String args) int n = 100; int m = 200; System.out.println(f(n,m); System.out.println(n); public static int f(int m, int n) n = m+n; return n; A.300 300 B.100 100 C.300 100 D.100 300 30.下列代码的输出结果是: public static void main(String args) int arr = 49, 81,77, 1, 98,50, 0, 80, 77, 18 ,11,15; 0,1,11, 15,18,49, 50,77, 77, 80, 81,98 Arrays.sort(arr); int index = Arrays.binarySearch(arr, 80); System.out.print(index+“”);/ 9 index = Arrays.binarySearch(arr, 90);/-index-1 System.out.print(index); A.9-12 B.8-11 C.8-1 D.9-1 31.以下是插入排序的部分代码,请把处补充完整 public static int insertSort(int ary) for (int i = 1; i = 0 ; j-) if(temp= 0 ; j-) if(temp= 0 ; j-) if(temp= 0 ; j-) if(temp if (asc)return; private static void swap(int arry, int i, int j) int temp = arryi; arryi = arryj; arryj = temp; A.for (int j = len-1; j i; j-) if (arryj = i; j-) if (arryj = i; j-) if (arryj arryj - 1) swap(arry, j, j - 1); asc = false; D.for (int j = len - 1; j = i; j-) if (arryj 处应该填入的代码是: public static void main(String args) int key = 16; int arry = 1, 3, 5, 7, 8, 10, 12, 15, 16 ; int low = 0; int high = arry.length - 1; while (low else System.out.println(mid); return; System.out.println(-1); A.int mid = (low + high) 1; if (arrymid key) low = mid + 1; else if (arrymid 1; if (arrymid key) high = mid - 1; C. int mid = (low + high) 1; if (arrymid key) high = mid; D.int mid = (low + high) 1; if (arrymid key) high = mid - 1; 34.使用递归算法求 10 的阶乘,下列选项正确的是: A. public static int method(int n) if (n 1) return 1; else return n * method(n - 1); D.public static int method(int n) if (n 1) return 1; else return n * (n - 1); 35.Java 语言可以跨平台的原因是: A.Java 面向对象 B.Java 虚拟机 C.Java 垃圾回收机制 D.Java 编译器 36.下列的注释方式能够支持 javadoc 命令: A. /*.*/ B./*.*/ C./ D./*.*/ 37.请看下列表达式不正确的是: A.String name2 = “Jane Doe“; B.int $age=24; C.Double _height = 123.5; D.double temp = 37.5; 38.下列选项中能正确编译的是: A. public static void main(String args) int one=12; System.out.println(one); B.public static void main(String args) one=12; System.out.println(one); C. public static void main(String args) int one; System.out.println(one); D.public static void main(String args) int one; int m=10; if(m0) one=12; System.out.println(one); 39.下列程序编译或运行的结果是: public static void main(String args) for(int i=0;i 下列选项中放置在处,使程序编译正确的是: A.p0 = p1; B.p1 =p2; C.p2 = p4; D.p2 = (ClassC)p1; 51.请看下列代码,程序的输出结果是: class One public One() System.out.print(1); class Two extends One public Two() System.out.print(2); class Three extends Two public Three() System.out.print(3); public class Numbers public static void main(String argv) new Three(); A.1 B.3 C.123 D.321 52.下列代码的运行结果是: public class Animal public String noise() return “peep“; public static void main(String args) Animal animal = new Dog(); Cat cat = (Cat)animal; System.out.println(cat.noise(); class Dog extends Animal public String noise() return “bark“; class Cat extends Animal public String noise() return “meow“; A.peep B.bark C.meow D.抛出运行时异常 53.下列代码的运行结果是: class SimpleCalc public int value; public void calculate() value += 7; public class MultiCalc extends SimpleCalc public void calculate() value -= 3; public void calculate(int multiplier) calculate(); super.calculate(); value *= multiplier; public static void main(String args) MultiCalc calculator = new MultiCalc(); calculator.calculate(2); System.out.println(“Value is: “ + calculator.value); A.Value is: 8 B.Value is: -8 C.Value is: 12 D.Value is: -12 54.下列选项不属于属性的可见性有: A.公有的 B.私有的 C.私有保护的 D.保护的 55.在 Java 中,关于 static 关键字的说法错误的是: A.static 可以修饰方法 B.static 可以修饰变量 C.static 可以修饰代码块 D.static 修饰的方法,在该方法内部可以直接访问非静态的成员变量 56.下列类的定义,错误的是: A.public class Test extends Object B.final class Operators C.class Point D.void class Point 57.在 Java 中,关于 final 关键字的说法正确的是: A.如果修饰局部变量,必须初始化 B.如果修饰类,则该类只能被一个子类继承 C.如果修饰方法,则该方法不能在子类中被覆盖 D.如果修饰方法,则该方法所在的类不能被继承 58.下列数组创建和初始化的方式不正确的是: A. public class Test02 static final int a = 100,200 ; B. public class Test02 static final int a; static a=new int2; a0=100; a1=200; C.public class Test02 final int a; public Test02() a=new int2; a0=100; a1=200; D.public class Test02 static final int a; static void init() a = new int3; a0=100; a1=200; 59.关于抽象类的说法正确的是 A.抽象类中一定包含抽象方法,否则是出现编译错误 B.包含抽象方法的类一定是抽象类 C.抽象方法可以没有方法体,也可以有方法体 D.抽象类的子类一定不是抽象类 60.关于接口的说法错误的是: A.接口是特殊的抽象类 B.接口是抽象方法和常量值的定义的集合 C.当一个非抽象类实现一个接口时,需要实现接口中的所有方法 D.多个类可以实现一个接口,一个类只能实现一个接口 61.下列不属于 Swing 提供的 Listener 的是: A.ActionListener B.MouseListener C.KeyListener D.MemeryListener 62.请看下列代码: public class Line public static class Point class Triangle 在处,需要创建 Point 类的对象,下列选项正确的是: A.Point p = new Point(); B.Line.Point p = new Line.Point(); C.Line line = new Line() ; line.Point p = new line.Point(); D.Line.Point p = new Line().new Point(); 63.程序执行的结果是: public class Test int x = 12; public void method(int x) x += x; System.out.println(x); public static void main(String args) Test t = new Test(); t.method(5); A.5 B.10 C.12 D.17 64.程序的执行结果是: 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 65.关于下列代码说法正确的是: public classCreditCard private String cardlD; private Integer limit; public String ownerName; public void setCardlnformation(String cardlD, String ownerName, Integer limit) this.cardlD = cardlD; this.ownerName = ownerName; this.limit = limit; A.类 CreditCard 是完全封装的 B.属性 ownerName 打破了封装 C.属性 cardlD 和 limit 打破了封装 D.方法 setCardlnformation 打破了封装 66.关于下列代码说法正确的是: public class A public void doit() public String doit() return “a“; public double doit(int x) return 1.0; A.无编译错误 B.代码 public String doit() 行,出现编译错误 C.代码 public double doit(int x) 行,出现编译错误 D.代码 return “a“;行处出现编译错误 67.关于下列代码说法正确的是: public class ItemTest privateint id; public ItemTest(int id) this.id = id; public void updateId(int newId) id = newId; public static void main(String args) ItemTest fa = new ItemTest(42); fa.updateId(69); System.out.println(fa.id); A.编译错误 B.运行时异常抛出 C.运行后,fa 对象属性 id 的值没有改变,应然是 42 D.运行后,fa 对象属性 id 的值改变成新的值 69 68.请看下列代码: public class Operator public String find() return “jessica“; public static void main(String args) System.out.println(op.find(); 如果运行上述代码,抛出 NullPointerException 异常,那么处应填入的代码是: A.Operator op=new Operator(); B.Operator op; C.Operator op=null; D.new Operator(); 69.给出下面的代码段: 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) w=d;z=c; 在处写下如下代码,正确的是: A.Base(a, b); B.super(a,b); C.x=a, y=b; D.this(a,b); 70.在 Java 中,所有类的基类是: A.java.lang.Object B.java.lang.Class C.java.applet.Applet D.java.awt.Frame 71.下列代码运行的结果是: class Foo public int a; public Foo() a = 3; public void addFive() a += 5; class Bar extends Foo public int a; public Bar() a = 8; public void addFive() this.a += 5; public class TestFoo public static void main(String args) Foo foo = new Bar(); foo.addFive(); System.out.println(“Value: “ + foo.a); A.Value: 3 B.Value: 8 C.Value: 13 D.Value: 18 72.程序的执行结果是: public class Test public static void main(String args) Child c = new Child(); class Father public Father() System.out.println(“父类无参构造函数“); public Father(String name) System.out.println(“父类有参构造函数“); class Child extends Father public Child() this(“dd“); System.out.println(“子类无参构造函数“); public Child(String name) super(“dd“); System.out.println(“子类有参构造函数“); A.父类有参构造函数 子类有参构造函数 子类无参构造函数 B.父类无参构造函数 子类有参构造函数 子类无参构造函数 C.子类有参构造函数 子类无参构造函数 父类无参构造函数 D.子类无参构造函数 子类有参构造函数 父类无参构造函数 73.下列代码的运行结果是: public class Animal public String noise() return “peep“; public static void main(String args) Cat cat =null; Animal animal = new Dog(); if (animal instanceof Cat) cat = (Cat) animal; System.out.println(cat.noise(); else System.out.println(“animal is not Cats instance“); class Dog extends Animal public String noise() return “bark“; class Cat extends Animal public String noise() return “meow“; A.peep B.bark C.meow D.animal is not Cats instance 74.请看下列代码: 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 int blipvert(int x) return 0; D.protected long blipvert(int x) return 0; 75.下面关于 import, class 和 package 的声明顺序正确的是: A.package, import, class B.class, import, package C.import, package, class D.package, class, import 76.请看下列代码: public class Foo static void alpha() /* more code here */ void beta() /* more code here */ 下列说法正确的是: A.Foo.beta()是调用 beta 方法的正确方式 B.Foo.alpha()是调用 alpha 方法的正确方式 C.beta 方法不可以直接调用 alpha 方法 D.alpha 方法可以直接调用 beta 方法 77.关于下列代码说法正确的是: public interface DoStuff2 float getRange(int low, int high); interface DoMore float getAvg(int a, int b, int c); abstract class DoAbstract implements DoStuff2, DoMore class DoStuff implements DoStuff2 public float getRange(int x, int y) return 3.14f; interface DoAll extends DoMore float getAvg(int a, int b, int c, int d); A.无编译错误 B.代码 abstract class DoAbstract implements DoStuff2, DoMore 行,编译错误 C.代码 interface DoAll extends DoMore 行,编译错误 D.代码 float getAvg(int a, int b, int c, int d);行,编译错误 78.请看下列代码编译和运行的结果是: public class Student private String name=“sun“; public static void main(String args) Student students=new Student2; System.out.println(); System.out.println(students.length); A.sun2 B.null2 C.null1 D.运行时抛出 NullPointerException 异常 79.下面程序定义了一个类,关于该类说法正确的是: abstract class AbstractClass A.可以使用 new AbstractClass();来实例化一个 AbstractClass 类的对象 B.该类不能被继承 C.该类的方法都不能被重载 D.该类的方法可以在子类中重写 80.下列代码的输出结果是: public class TestString public static void main(String args) String str = “420“; str += 42; System.out.print(str); A.42 B.420 C.462 D.42042 81.下列代码编译和运行的结果是: public class Foo public static void test(String str) int check = 4; if (check = str.length() System.out.print(str.charAt(check -= 1) + “, “); else System.out.print(str.charAt(0) + “, “); public static void main(String args) test(“four“); test(“tee“); test(“to“); A.r, t, t, B.r, e, o, C.编译失败 D.抛出运行时异常 82.下列代码的运行结果是: String test = “This is a test“; String tokens = test.split(“s“); System.out.println(tokens.length); A.0 B.1 C.3 D.4 83.请看下列代码: public static void main(String args) Date date = new Date(); System.out.println(date); 假设当前时间是 2013 年 1 月 24 日 10 点 33 分 52 秒 星期四,程序输出的结果是: A.2013-01-24 10:33:52 Thu B.2013-01-24 10:33:52 星期四 C.2013 年 1 月 24 日 10 点 33 分 52 秒 星期四 D.Thu Jan 24 10:33:52 CST 2013 84.把当前时间转换为字符串“2013-01-24”的形式,下列选项正确的是: A.SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-mm-dd“); Date date = new Date(); String dateStr = sdf.format(date); B.SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-mm-dd“); Date date = new Date(); String dateStr = sdf.parse(date); C.SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd“); Date date = new Date(); String dateStr = sdf.format(date); D.SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd“); Date date = new Date(); String dateStr = sdf.parse(date); 85.下列代码的运行结果是: public class Converter public static void main(String args) Integer i = 12; int j = 12; System.out.println(“It is “ + (j = i) + “ that j=i.“); A. It is true that j=i B.It is false that j=i C.运行时抛出异常 D.编译出错 86.下列代码编译和运行的结果是: public static Collection get() Collection sorted = new LinkedList(); sorted.add(“B“); sorted.add(“C“); sorted.add(“A“); return sorted; public static void main(String args) for (Object obj : get() System.out.print(obj + “, “); A.A, B, C, B.B, C, A, C.无输出 D.编译错误 87.请看下列代码: int myArray=new int 1, 2,3,4, 5; 下列选择中,能把 myArray 数组转换成 List 容器的是: A.List myList = myArray.asList(); B.List myList = Arrays.asList(myArray); C.List myList = new ArrayList(myArray); D.List myList = Collections.fromArray(myArray); 88.题示代码的功能为:对于一个存放 Integer 对象的 ArrayList,内容为:1,2,3,对其进行循 环遍历: List list=new ArrayList(); list.add(1); list.add(2); list.add(3); for(int i=0;i intList = new ArrayList(); append(intList); System.out.println(intList.get(0); A.42 B.0042 C.抛出运行时异常 D.编译错误 91.题示代码的功能为:对于一个存放 Person 对象的 ArrayList 进行循环遍历,并取到每个 Person 对象的 idCard 和 userName。 public class Person private Long idCard; pirvate String userName; /以下是 getter 和 setter 方法 List list=new ArrayList(); Person p1=new Person(); p1.setIdCard(new Long(1001); p1.setUserName(“terry”); Person p2=new Person(); p2.setIdCard(new Long(1002); p2.setUserName(“tom”); list.add(p1); list.add(p2); for(插入代码)

温馨提示

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

评论

0/150

提交评论