可以使用的,下面是一个例子:
class Demo
{
public static void main(String[] args)
{
Person p=new Person("zhangsan");
}
}
class Person
{
public String name;
public Person(String name)
{
this.name=name;
try
{
Thread.sleep(10000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println("name:"+name);
}
}
Thread.sleep();会抛出异常,只要将异常处理了就可以使用了 |