myfunc(); } }
A.输出结果为 My Func
B.编译指示 Base 类中无抽象方法
C.编译通过,但运行时指示Base 类中无抽象方法
D.编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。 8) 以下程序的调试结果为? class Base{
public final void amethod(){
System.out.println(\ } }
public class Fin extends Base{
public static void main(String argv[]){ Base b = new Base(); b.amethod(); } }
A.编译指示带有final 方法的类自己必须定义为final B.编译指示不能继承含有final 方法的类 C.运行错误,原因是Base类没有定义为final类 D.运行输出 amethod
9) 在同一目录编译和运行以下两文件结果如何? //文件 P1.java package MyPackage; class P1{
void afancymethod(){
System.out.println(\ } }
//文件 P2.java
public class P2 extends P1{
public static void main(String argv[]){ P2 p2 = new P2();
p2.afancymethod(); } }
A.两个均通过编译,P2运行时输出 What a fancy method B.没一个通过编译
C.两个均通过编译,但P2运行时出错 D.P1 通过编译,但P2出现编译错误 10)以下程序的调试结果为? public class Outer{
public String name = \ public static void main(String argv[]){ Inner i = new Inner(); i.showName(); }
private class Inner{
String name =new String(\ void showName(){
System.out.println(name); } } }
A.输出结果 Outer B.输出结果 Inner
C.编译错误,因Inner类定义为私有访问 D.在创建Inner类实例的行出现编译错误 11) 设有如下代码: class Base{}
public 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处插入哪个代码将不出现编译和运行错误。 A.b=m; B.m=b; C.d =i; D.b1 =i; 12) 设有如下代码: interface IFace{}
class CFace implements IFace{} class Base{}
public 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处插入哪个代码将不出现编译和运行错误。 A.obj1=obj2; B.b=obj; C.obj=b; D.obj1=b; 13) 设有类定义如下: class Base{ public Base(int i){} }
public class MyOver extends Base{ public static void main(String arg[]){ MyOver m = new MyOver(10); }
MyOver(int i){ super(i); }
MyOver(String s, int i){ this(i); //Here } }
以下哪条语句可以安排在//Here处 ? A.MyOver m = new MyOver(); B.super(); C.this(\ D.Base b = new Base(10); 14) 设有类定义如下: class InOut{
String s= new String(\ public void amethod(final int iArgs){ int iam; class Bicycle{
public void sayHello(){ //Here } } }
public void another(){ int iOther; } }
以下哪些语句可以安排在//Here处 ? A. System.out.println(s); B.System.out.println(iOther); C. System.out.println(iam); D. System.out.println(iArgs); 九、常用系统类
1) 关于以下程序段,正确的说法是 1. String s1=\ 2. String s2=\ 3. if(s1= =s2)
4. System.out.println(\ 5. if (s1.equals(s2))
6. System.out.println(\ A. 行4与行6都将执行 B. 行4执行,行6不执行
C. 行6执行,行4不执行 D. 行4、行6都不执行
2) 要产生[20,999]之间的随机整数使用哪个表达式? A.(int)(20+Math.random()*979) B. 20+(int)(Math.random()*980) C. (int)Math.random()*999 D. 20+(int)Math.random()*980 3) 下列程序运行的结果为: public class Example{
String str=new String(\ char[] ch={'a','b','c'};
public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+\ Sytem.out.print(ex.ch); }
public void change(String str,char ch[]){ str=\ ch[0]='g'; } }
A. good and abc B. good and gbc C. test ok and abc D. test ok and gbc 4) 设有如下程序 public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]); int i = intObj.intValue(); if(args.length > 1) System.out.println(i); if(args.length > 0)
System.out.println(i - 1);