2012年5月21日

摘要: 如果我们需要定义一个父类,此父类能为其子类声明结构却不能为方法定义有意义的实现过程。也就是说,有时候我们需要创建一个父类。此父类只定义可被其所有子类共享的一般形式,而让子类来补充细节,这种类就是抽象类。抽象类的声明:如果使用abstract 修饰一个类,这个类就是抽象类。抽象类创建的语法格式如下:abstract class 类名{ //抽象类的实现代码}例如,下面创建一个员工抽象类Employee:abstract class Employee{ int basic_salary=2000; abstract void salary();} abstract 修饰符可与类和方法一起使用,来. 阅读全文
posted @ 2012-05-21 20:37 wiches 阅读(249) 评论(0) 推荐(0) 编辑

2012年5月16日

摘要: 下面程序 创建了三个子线程public class thread {public static void main(String args[]){new NewThread("One");new NewThread("Two");new NewThread("Three");try{Thread.sleep(10000);}catch(InterruptedException e){System.out.println("main thread interrupted");}System.out.println(& 阅读全文
posted @ 2012-05-16 20:45 wiches 阅读(113) 评论(0) 推荐(0) 编辑
 
摘要: 创建线程的另一个途径是创建一个新类来扩展Thread类,然后再创建该类的实例。当一个类继承Thread时。它必须重载run()方法,这个run()方法是新线程的入口,同时,它也必须调用start()方法去启动新线程的执行,下面用扩展thread类重写上一个的程序,public class thread2 {public static void main(String args[]){new NewThread(); //creat a new threadtry{for(int i=5;i>0;i--){System.out.println("main thread:" 阅读全文
posted @ 2012-05-16 20:45 wiches 阅读(172) 评论(0) 推荐(0) 编辑

2012年5月15日

摘要: public class thread1 {public static void main(String args[]){new NewThread(); //creat a new threadtry{for(int i=5;i>0;i--){System.out.println("main Thread:"+i);Thread.sleep(1000);}}catch(InterruptedException e){System.out.print("main threa interrupted.");}System.out.print(&quo 阅读全文
posted @ 2012-05-15 21:11 wiches 阅读(280) 评论(0) 推荐(0) 编辑