Java笔试经典题库1.下列选项对Java中的继承描述错误的是()。
A.子类至少有一个基类B.子类可作为另一个子类的基类C.子类除了包含其直接定义的属性外,还包含其父类的私有属性D.子类继承父类的方法访问权限保持不变2.如果try {}中有一个return语句,那么紧跟在此try后的finally {}中的代码会不会被执行,什么时候被执行()。
A.不会执行B.会执行,在return前执行C.会执行,在return后执行D.会执行,可能在return前执行,也可能在return后执行3.构造方法是否可以被重写和重载()。
A.不能重写,可以重载B.可以重写,不能重载C.不能重写,不能重载页脚内容1D.可以重写,可以重载4.下列选项属于方法重载的优势的有()。
【选两项】A.实现多态B.方法名的复用C.提高程序运行速度D.使用方便,提高可读性5.面向对象方法的多态性是指()。
A.一个类可以派生出多个特殊类B.一个对象在不同的运行环境中可以有不同的变体C.拥有相同父类或接口的不同对象可以以适合自身的方式处理同一件事D.一个对象可以是由多个其他对象组合而成的6.Dog是Animal的子类,则下列代码错误的是()。
A.Animal a = new Dog();B.Animal a = (Animal )new Dog();C.Dog d = (Dog)new Animal();D.Object o = new Dog() ;7.下列定义Java的常量,错误的是()。
页脚内容2A.public static final double PI = 3.14;B.public final static double PI = 3.14;C.final public static double PI = 3.14;D.static public double final PI = 3.14;8.如下代码段的输出结果是()。
try{System.out.print("try,");return;} catch(Exception e){System.out.print("catch,");} finally {System.out.print("finally");}A.try,B.try,catch,C.try,finallyD.try,catch,finally页脚内容39.如下代码段方法的返回值是()。
public int count() {try{return 5/0;} catch(Exception e){return 2*3;} finally {return 3;}}A.0B.6C.3D.程序错误10.如下代码段的运行结果是()。
public class Car {页脚内容4public void run(){System.out.println("汽车在跑");}}public class Benz extends Car {public void run(){System.out.println("奔驰在跑");}}public static void main(String[] args) {Car car = (Car)( new Benz() );car. run();}A.汽车在跑B.奔驰在跑C.无法编译D.运行时将抛出异常页脚内容511.王强使用log4j的配置文件如下:log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.out…log4j.rootLogger=info, stdout, file如果他在程序中的编写如下,则将会输出的日志信息是()。
logger.debug("记录debug日志");("记录info日志");A.记录debug日志记录info日志B.记录debug日志C.记录info日志D.程序错误,无法输出日志12.下面的异常处理代码段的输出结果是()。
try{int result = 6/0;页脚内容6System.out.print("try,");} catch(ArithmeticException e1) {System.out.print("ArithmeticException异常,");throw new Exception();} catch(Exception e2) {System.out.print("Exception异常,");} finally {System.out.print("finally");}A.程序错误B.ArithmeticException异常,finallyC.ArithmeticException异常,Exception异常,finallyD.try,ArithmeticException异常,Exception异常,finally 13.关于Java的接口,下列说法错误的是()。
A.可以被继承B.可以只定义常量,而没有任何方法页脚内容7C.可以这样定义常量:public int EVEREST = 8848;D.方法的参数不可以是接口14.如下代码段的输出结果是()。
public class Example {String str = new String("good");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+" and ");System.out.println(ex.ch);}public void change(String str,char ch[]){str="test ok";ch[0]='g';}}页脚内容8A.good and abcB.good and gbcC.test ok and abcD.test ok and gbc15.下列选项中,能与public void methodA(){ }形成重载的有()。
(空格)A.private void methodA(){ }B.private int methodA(){ return 1;}C.public void methodA(int a){ }D.public void methodA() throws Exception{ }16.下列选项中,子类中能与父类public void methodA(int a){ }方法形成重写的有()。
(空格)A.public int methodA(int a){return 1;}B.public void methodA(int a) throws Exception{ }C.private void methodA(int a){ }D.public void methodA(int b){ }17.关于构造方法,下列说法错误的有()。
【选三项】A.父类只有一个带参的构造方法,子类必须显示声明带参构造方法B.子类无参构造方法中没有写super();时,不会调用父类无参构造方法页脚内容9C.子类无参构造方法不可以用super(int a);调用父类对应的带参构造方法D.实例化一个类的对象时,一定会先调用ng.Object的构造方法18.分析下面的代码,其将会输出()。
public class Testa {Integer a = new Integer(10);Integer b = new Integer(10);public static void main (String[ ] args){Testa testA = new Testa();if (testA.a==testA.b){System.out.print("很");}if (testA.a.equals(testA.b)){System.out.print("好");}}}A.很页脚内容10B.好C.很好D.抛出NullPointerException异常19.分析如下代码:String s = null;则下列选项中会抛出NullPointerException异常的有()。
【选两项】A.if( (s!=null) & (s.length()>0) )B.if( (s!=null) && (s.length()>0) )C.if( (s==null) | (s.length()==0) )D.if( (s==null) || (s.length()==0) )20.分析下面的代码,在B类注释处可以放置的方法有()。
【选三项】class A {public void method(int a,float b){//一些声明等}}public class B extends A {页脚内容11//此处放置方法}A.private void method(int i,float a) {…}B.public void method(int i,float f) {…}C.public void method() {…}D.private int method(float f,int b) {…}21.编译运行如下程序,会发生()的情况。
public class Mystery {String s;public static void main(String args[ ] ) {Mystery m =new Mystery();m.go();}public void Mystery() {s ="Constructor";}页脚内容12private void go(){System.out.println(s);}}A. 可以编译,运行时会抛出异常B. 可以编译运行,但是控制台上什么都不会输出C. 输出“constructor”D. 输出“null”22.关于Java的异常和异常处理,下列说法错误的有()。