package com.cws; public class Demo10_1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Cat cat = new Cat(); cat.start(); Dog dog = new Dog(); Thread t = new Thread(dog); t.start(); } } class Dog implements Runnable{ int i =0; @Override public void run() { while(true){ i++; try { Thread.sleep(1000); System.out.println("1+1=2!"); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } if(i==10){ break; } } } } class Cat extends Thread{ int i = 0 ; public void run(){ while(true){ i++; try { this.sleep(1000); System.out.println("hello word !"); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } if(i==10){ break; } } } }