Java基础试题及其答案 (1)(16页).doc
《Java基础试题及其答案 (1)(16页).doc》由会员分享,可在线阅读,更多相关《Java基础试题及其答案 (1)(16页).doc(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-Java基础试题及其答案 (1)-第 16 页Java试题1) java程序中,main方法的格式正确的是()。 (选择一项) a)static void main(String args) b)public void main(String args) c)public static void main(Strings)d)public static void main(String args)2) 给定java代码,如下: public byte count(byte b1,byte b2) return_; 要使用这段代码能够编译成功,横线处可以填入() 。 (选择一项)a) (byt
2、e) (b1-b2) b) (byte) b1-b2 c) b1-b2 d) (byte) b1/b23) 在Java中,在包com.db下定义一个类,要让包com.util下的所有类都可以访问这个类,这个类必须定义为()。 (选择一项) a)protected b)private c)public d)friendly4) 在Java中,下列()语句不能通过编译。 (选择一项) a) String s= “join”+ “was”+ “here”; b) String s= “join”+3; “”+new Person() toString()c) int a= 3+5d) float f
3、=5+5.5; 5.5 double 5.5f float6)给定java代码如下,运行时,会产生()类型的异常。(选择一项) String snull; s.concat(“abc”); a)ArithmeticException b)NullPointerException c)IOException d)EOFException 已到文件尾,再读取抛出7) 在java中,()对象可以使用键/值的形式保存数据。 (选择一项) a)ArrayList List 有序可重复 b) HashSet Set 无序不可重复 同一对象是重复的 c) HashMap Map(key/value) 重复定
4、义:hashCode、equals(业务) d) LinkedList List8) 给定如下java代码,编译运行之后,将会输出()。 public class Test public static void main(String args) int a=5; System.out.println(a%2=1) ?(a+1) /2:a/2) ; 三目表达式 (选择一项) a)1 b)2 c)2.5 d)39) 以下Java语句中,String str = “123456789”;str =str.subString(1,3);执行后str中的值为。(选择一项) subString子串 1,
5、 3)a) “23” b) “123”c) “12”d) “234”10) 给定如下java代码,以下()代码行编译会报错。(选择一项) class MyClassprivate final int a; 错误,类中属性是final时,必须赋初值 void myMethod(final int p) final int il;正确,函数中变量是final时,定义时可以不赋值 final int i2=p; 正确,函数中变量是final时,定义时可以赋初值 i1=20; 正确,因为它还没有赋初值,但是赋值后不能更改 i2=20; 错误,因为常量已赋值,不能更改a) void my Method(
6、final int p) b) final int il;c) final int i2=pd) il=20e) i2=20;11) 给定如下java代码,编译时会在()出现错误。 class Parent class Child extends Parent public static void main(String args) Parent p1=new Child() ;/第一行 正确,子类向父类是自动造型 Parent p2=new Parent () ;/第二行 Child c1=new Child() ;/第三行 Child c2=new Parent () ;/第四行 错误,父
7、类向子类是强制造型 (选择一项) a) 第一行b) 第二行c) 第三行d) 第四行12)给定某java程序的main方法,如下:public static void main (Stringarg) System.out.print( “Hello”+args1) ;从命令行传参:people world nation,该程序的运行结果是()。 (选择一项)a) Hello people args:“people”, “world”, “nation”b) Hello worldc) Hello people world nationd) 运行时出现异常13) 给定Java代码,如下: abs
8、tract class Shape abstract void draw() ; 方法重写规则 要创建Shape类的子类Circle,以下代码正确的是() (选择二项)a) class Circle extends Shape int draw() 返回类型是int,不正确,应该是intb) abstract class Circle extends Shape c) class Circle extends Shape void draw() ; 无方法体d) class Circle extends Shape void draw() 14) 给定如下java代码,编译运行时,结果是()。
9、 (选择一项)public class Test public static void main (String args) for (int i=0;i3; i+) System.out.print(i) ; System.out.print(i) ; i的作用域是在for循环内 a) 编译时报错 b) 正确运行,输出012 c) 正确运行,输出123 d) 正确运行,输出012315) 给定一个Java程序的方法结构如下;以下方法体实现语句正确的是( )。(选择两项)public Integer change( int i) a) Integer int =new Integer( i)
10、; 变量名int是关键字return int;b) Integer t = Integer.valueOf( i) ;return t;c) return new Integer( i) ;d) return i; JDK1.5之后支持基本类型和对象类型的自动转换16) 在java中,在尝试对null 对象操作时,会产生( )类型的异常。(选择一项)a) ArithmeticExceptionb) NullPointerExceptionc) IOExceptiond) EOFException6) 17) Java语言中,String str=”123456789”,System.out.p
11、rintln(str.indexOf(“5”),输出结果为()。(选择一项) indexOf定位,下标从0开始a) 6b) 5c) 4d) -118) 在java中,已定义两个接口B和C,要定义一个实现这两个接口的类,以下语句正确的是( ) 。(选择一项) a) interface A extends B,C 接口b) interface A implements B,C 接口c) class A implements B,Cd) class A implements B,implements C19)给定JAVA代码,如下:Class Parent public void count() S
12、ystem.out.println(10%3) ;public class Test extends Parent public void count() System.out.println(10/3) ;public static void main(String args) Parent p = new Test() ; p.count() ; 这里实际是调用具体类(Test)的count方法,如果要调用Parent的count,那么需要在Test中如下写: public void count() super.count(); 使用super引用父类 System.out.println
13、(10/3) ;在调有重写方法时,首先在子类找,如果子类中没有,则自动查找父类,直到找到一个为止。如果子类有,则调用子类中重写方法,这时父类中的重写方法不会再自动查找,如果要调用,则需要在子类重写方法中使用super来显示调用。运行编译后,输出结果是( )。(选择一项)a) 1b) 1.0c) 3d) 3.333333333333333520) 在Java中,下列( )是不合法的赋值语句。(选择一项)a) float f=1/3;b) int i=1/3;c) float f=1*3.0; 3.0 doubled) double f=1.0/3;21) 利用JAVA SWING 编程,要在当前
14、窗体中显示如下信息提示框,则需要编写的代码是( )。(选择一项)a) JOptionPane.showMessageDialog(null,请输入登陆名!,提示信息,JOptionPane.CLOSED_OPTION) ;b) new JOptionPane.showMessageDialog(null,请输入登陆名!,提示信息,JOptionPane.CLOSED_OPTION) ;c) new JOptionPane.messageDialog(null,请输入登陆名!,提示信息,JOptionPane.CLOSED_OPTION) ;d) JOptionPane.messageDialo
15、g(null,请输入登陆名!,提示信息,JOptionPane.CLOSED_OPTION) ;22) 给定某java程序的main方法,如下;(选择一项)public static void main(String args) int i = 0;System.out.println(i+) ; i+表示本语句执行完成后,再执行+操作a) 0b) 1c) 编译错误d) 运行时出现异常 23)给定java程序,如下:编译运行Test.java,结果是( )。(选择一项)public class Testprivate static final int counter=10;public sta
16、tic void main(String args) System.out.println(+counter) ; +counter修改常量值,是错误的a) 10b) 11c) 编译错误d) 运行时出现异常24)在JAVA中,要创建一个新目录,要使用( )类的实例。(选择一项)a) File 文件和目录b) FileOutputStrean 文件输出字节流c) PrintWriter 输出字符流d) Dir 没有这个类25) 在java 中,下列( ) 类不能派生出子类. (选择一项) a) public class MyClass b) class MyClass c) abstract c
17、lass MyClass 表示抽象类,不能实例化d) final class MyClass 表示具体类,不能派生子类26) 在java 中,以下()命令能够将java源文件编译为类文件(选择一项)a) java 运行命令b) javaw 运行命令c) javac 编译命令d) jar 打Jar包 归档命令27)在JAVA中,通过调用以下( )方法,可以装载SUN的JDBC-ODBC桥。(选择一项)a) new Class() .load(“sun.jdbc.odbc.jdbcodbcDriber”) ;b) new Class() .forName(“sun.jdbc.odbc.JdbcOd
18、bcDriver”) ;c) Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”) ;d) Class.load(“sun.jdbc.odbc.JdbcOdbcDriver”) ;28) 在JAVA中,要判断D盘下是否存在文件abc.txt,应该使用以下( )判断语句。(选择一项)a) if(new File(“d:abc.txt”) .exists() = =1) b) if(File.exists(“d:abc.txt”) = =1) c) if(new File(“d:/abc.txt”) .exists( ) ) exists( ) 直接返回布尔值
19、d) if(File.exists(“d:/abc.txt) 29) 在JAVA接口中,下列选项里有效的方法声明是( )。(选择二项)a) public void aMethod( ) ; 接口中的方法声明中,范围只能是public和默认b) void aMethod( ) ;c) static void aMethod( ) ;d) protected void aMethod( ) ;30) 给定JAVA代码,如下:编译运行,结果是( )。(选择一项)public static void main(string args) String s;System.out.println(“s=”+
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java基础试题及其答案 116页 Java 基础 试题 及其 答案 16
限制150内