1、java笔试题含答案Java 笔试题(可多选)1. 下面哪些是Thread类的方法( ABD)A start() B run() C exit() D getPriority()2. 下面关于类的说法正确的是(A)A 继承自Throwable B Serialable C 该类实现了Throwable 接口D 该类是一个公共类3. 下面程序的运行结果是( false )String str1 = hello;String str2 = he + new String(llo); = str2);4.下列说法正确的有( C)A class中的constructor不可省略B constructo
2、r必须与class同名,但方法不能与class同名C constructor在一个对象被new时执行D一个class只能定义一个constructor5. 指针在任何情况下都可进行, =, =, =运算?( true )6. 下面程序的运行结果:(B)public static void main(String args) Thread t = new Thread() public void run() pong(); ; (); ping); static void pong() pong);A pingpong B pongping C pingpong和pongping都有可能 D 都
3、不输出7. 下列属于关系型数据库的是(AB)A. Oracle B MySql C IMS D MongoDB8. GC(垃圾回收器)线程是否为守护线程?( true )9. volatile关键字是否能保证线程安全?( false )10. 下列说法正确的是(AC)A LinkedList继承自ListB AbstractSet继承自SetC HashSet继承自AbstractSetD WeakMap继承自HashMap11. 存在使i + 1 i的数吗?( 存在 )12. 的数据类型是(B)A float B double C Float D Double13. 下面哪个流类属于面向字符
4、的输入流(A )ABufferedWriterBFileInputStreamCObjectInputStreamD InputStreamReader 14. Java接口的修饰符可以为(CD)A private B protected C final D abstract15. 不通过构造函数也能创建对象吗(A)A 是 B 否16. ArrayList list = new ArrayList(20);中的list扩充几次(A)A 0 B 1 C 2 D 317. 下面哪些是对称加密算法(AB)A DES B AES C DSA D RSA18.新建一个流对象,下面哪个选项的代码是错误的?
5、(B)A)new BufferedWriter(new FileWriter();B)new BufferedReader(new FileInputStream();C)new GZIPOutputStream(new FileOutputStream();D)new ObjectInputStream(new FileInputStream();19. 下面程序能正常运行吗( yes )public class NULL public static void haha() haha); public static void main(String args) (NULL)null).hah
6、a(); 20. 下面程序的运行结果是什么()class HelloA public HelloA() HelloA); Im A class); static static A); public class HelloB extends HelloA public HelloB() HelloB); Im B class); static static B); public static void main(String args) new HelloB(); Static A Static BHello AIm A classHelp BIm B Class21.getCustomerIn
7、fo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中产生了一个IOException,将会输出什么结果(A)public void getCustomerInfo() try 下面代码的运行结果为:(C)import .*;import .*;public class foo public static void main (String args) String s; s= + s); A代码得到编译,并输出“s=”B代码得到编译,并输出“s=null”C由于String s没有初始化,代码不能编译通过D代码得到编译,但捕获到NullPointException异常23. 5
8、 + 2);的输出结果应该是(A)。A52 B7 C2 D524.指出下列程序运行的结果(B)public class Example String str = new String(good); char ch = a, b, c ; public static void main(String args) Example ex = new Example(); , ; + and ); public void change(String str, char ch) str = test ok; ch0 = g; A、good and abcB、good and gbcC、test ok a
9、nd abcD、test ok and gbc25.要从文件中读出第10个字节到变量c中,下列哪个方法适合?(AB)AFileInputStream in=new FileInputStream(); (9); int c=();BFileInputStream in=new FileInputStream(); (10); int c=();CFileInputStream in=new FileInputStream(); int c=();DRandomAccessFile in=new RandomAccessFile(); (9); int c=();26.下列哪种异常是检查型异常,
10、需要在编写程序时声明(C)A NullPointerException B ClassCastException C FileNotFoundException D IndexOutOfBoundsException27. 下面的方法,当输入为2的时候返回值是多少?(D)public static int getValue(int i) int result = 0; switch (i) case 1: result = result + i; case 2: result = result + i * 2; case 3: result = result + i * 3; return r
11、esult;A 0 B 2 C 4 D 10Switch 也需要Break28.选项中哪一行代码可以替换题目中阅读Shape和Circle两个类的定义。在序列化一个Circle的对象circle到文件时,下面哪个字段会被保存到文件中?(B )class Shape public String name;class Circle extends Shape implements Serializable private float radius; transient int color; public static String type = Circle;A nameBradiusCcolor
12、Dtype父类为继承Serializable接口,其成员不能被序列化,静态变量和transient修饰的不能被序列化30.下面是People和Child类的定义和构造方法,每个构造方法都输出编号。在执行new Child(mike)的时候都有哪些构造方法被顺序调用?请选择输出结果(D )class People String name; public People() public People(String name) = name; class Child extends People People father; public Child(String name) = name; father = new People(name + :F); public Child() A 312 B 32 C 432 D 132