为什么此处e没有被实例化就可以直接调用printStackTrace()方法? 本帖最后由 henha2jiang 于 2012-08-11 12:42:52 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class Test1{ public static void main(String args[]) { MyThead mt = new MyThead(); mt.start(); for(int i = 0;i<10;i++) { try { Thread.sleep(1000); } catch(InterruptedException e) { e.printStackTrace(); } System.out.println(i+"ThreadDemo"); } }}class MyThead extends Thread{ public void run() //重写run方法 { for(int i=0;i<10;i++) { try { Thread.sleep(1000); //使用sleep方法让当前线程休眠1000毫秒 } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(i+"MyThread"); } }} 这就类似于函数参数,是别人实例化好了才传递给你的。public void fun(InterruptedException e) { e.printStackTrace();}你可以理解为Thread.sleep()这个函数,内部有这么一句话: throw new InterruptedException(); InterruptedException e语句里面前面是Exception 类型,后面是随便安的名字,用类名调用Thread的...方法,是异常里面的方法哈,查API看就知道了,不是很明了吗。 说错了,是异常抛出的对象,不是Thread。 去掉String中不想要的部分 如何理解面向抽象和面向接口 jbuilder2005编译老出现空指针异常,请大虾帮帮看看源代码。感激不尽 弱弱的问一个:二维坐标的问题? 窗体在屏幕中的位置怎么定位阿 [求助]请问怎么实现GUI动态显示模型层的数据?在线等.......小弟谢谢了 怎么让滚动条自动下滑? 我只是想写一个简单的java文件。请问forte的类路径该怎么设置的? 请问,那里能下载JBuilder5企业版? JAVA求助 java swing 怎么实现窗口振动效果 一个关于代码设计模式的问题
public class Test1
{
public static void main(String args[])
{
MyThead mt = new MyThead();
mt.start();
for(int i = 0;i<10;i++)
{
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.out.println(i+"ThreadDemo");
}
}
}class MyThead extends Thread
{
public void run() //重写run方法
{
for(int i=0;i<10;i++)
{
try
{
Thread.sleep(1000); //使用sleep方法让当前线程休眠1000毫秒
} catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println(i+"MyThread");
}
}
}
e.printStackTrace();
}
你可以理解为Thread.sleep()这个函数,内部有这么一句话:
throw new InterruptedException();