读代码分析结果
来源:互联网 发布:淘宝无法提交订单 编辑:程序博客网 时间:2024/05/16 19:19
读代码分析结果答案在最后,先做再看!
阅读代码段,看是否有错,如果有错。请写出并改正!如果没有,写出结果!
一、
public class ExceptionTest { public static void main(String[] args) { try { String str = null; System.out.println(str.length()); } catch (NullPointerException e) { System.out.println("a"); } catch (RuntimeException e) { System.out.println("b"); } finally { System.out.println("c"); } }}
二、
public class Forest implements Serializable { private Tree tree = new Tree(); public static void main(String[] args) { Forest f = new Forest(); try { FileOutputStream fs = new FileOutputStream("forest.set"); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(f); os.close(); } catch (Exception e) { e.printStackTrace(); } } class Tree { ; };}
三、
public class Hello { String title;// null int value;// 0 public Hello() { title = "World"; } public Hello(int value) { this.value = value; title = "Hello"; Hello(); } public static void main(String[] args) { Hello h = new Hello(); System.out.println(h.title); }}
四、
public class IfTest { interface DeclareStuff { public static final int SKEY = 3; void doStuff(int x); } public class TestDeclare implements DeclareStuff { public void doStuff(int x) { x += SKEY + ++x; System.out.println(x); } } public static void main(String[] args) { int x = 5; new IfTest().new TestDeclare().doStuff(++x);//6 }}
五、
public class ThreadTest implements Runnable { public static void main(String[] args) throws Exception { Thread t = new Thread(new ThreadTest()); t.start(); System.out.println("Start"); t.join(1000); System.out.println("Compliete"); } public void run() { for (int i = 0; i < 4; i++) { System.out.println(i); } }}
六、
public class TimerTest { public static void appendList(List list) { list.add("test"); } public static void main(String[] args) { List<Integer> aalist = new ArrayList<Integer>(); aalist.add(11); appendList(aalist); System.out.println(aalist.get(1)); }}
第一题:
a
c第二题:
报错 java.io.NotSerializableException: com.test.offer.Forest$Tree
因为:一个可序列化的类,必须要求他的变量也是可序列化的,要是变量不能被序列化那这个类就不能被序列化第三题:
World第四题:
16第五题:
Start
0
1
2
3
Compliete第六题:
test
阅读全文
0 0
- 读代码分析结果
- 读代码,写结果
- 读代码,写结果
- 读代码,写结果
- java中代码检查checkStyle结果分析
- java中代码检查checkStyle结果分析 .
- java中代码检查checkStyle结果分析
- fortify代码扫描问题结果分析
- 写出以下代码执行结果,分析为什么?(没有分析结果不得分)
- 黑马程序员——写出以下代码执行结果,分析为什么?(没有分析结果不得分)
- Linux代码性能检测利器(四)- 获取分析结果
- [Tensorflow]3.DCGAN代码及实验结果分析
- cs231n assigment1 KNN部分代码运行结果及分析
- 第一章代码和结果
- 下面代码的结果
- 函数结果状态代码
- 表空间分析结果
- google 结果分析正则
- UVA 10652 Board Wrapping(凸包求面积 刘汝佳训练指南模板)
- Android APP 签名和上传到市场
- @Transactional 事务回滚 分析
- iOS第三方库汇总
- equals与==的区别。
- 读代码分析结果
- 【笔试】37互娱 补全程序使Java断言成立
- 捕鱼小游戏
- 通过脚本生成oracle的ODBC连接
- DLL或exe破解步骤
- PAT--1075. PAT Judge
- makefile文件入门
- HDU-5773 The All-purpose Zero(LIS变形)
- 微店打印机如何自动接单和批量打印订单(教程)