黑马程序员技术交流社区

标题: 暴力的代码 [打印本页]

作者: long362144768    时间: 2013-12-5 01:15
标题: 暴力的代码
  1. public class nomain {
  2.         static{
  3.                 System.out.println("hello");
  4.                 try {
  5.                         int i = 1/0;
  6.                 } catch (Exception e) {
  7.                         System.exit(0);
  8.                 }finally{
  9.                         System.out.println("world");
  10.                 }
  11.         }
  12. }
复制代码

看看能打印出什么?
作者: 汪洋大海    时间: 2013-12-5 06:11
错误: 在类 nomain 中找不到主方法, 请将主方法定义为:
   public static void main(String[] args)

话说同学,你是在美国吗?半夜来发帖。
作者: kongling    时间: 2013-12-5 09:18
打印"hello"
如果,调用System.exit()方法后,即使是fianlly{},里的代码也不会再执行,直接退出虚拟机。
作者: 珊湖礁    时间: 2013-12-5 10:51
打印hello,后面的的world不会显示
作者: 王家胜    时间: 2013-12-5 14:23
本帖最后由 王家胜 于 2013-12-5 14:24 编辑

没有入口函数是启动不了的
错误: 找不到或无法加载主类 main
你要表达的意思的程序是
  1. import java.io.File;

  2. public class nomain {
  3.     static{
  4.             System.out.println("hello");
  5.             try {
  6.                     int i = 1/0;
  7.             } catch (Exception e) {
  8.                     System.exit(0);
  9.             }finally{
  10.                     System.out.println("world");
  11.             }
  12.     }
  13.     public static void main(String[] args) {
  14.                
  15.         }
  16. }
复制代码



作者: chick2018    时间: 2013-12-5 14:27
实际上是编译错误
作者: 简★零度    时间: 2013-12-5 23:03
下次问题解决了就把类型改成提问结束!谢谢!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2