//继承法示例:受限于单继承的局限性
class Student extends Thread
{
public void run()//重写Runnable中的run方法
{
for(int x=0;x<100;x++)
{
System.out.println(Thread.currentThread().getName()+"-------"+x);
}
}
}
class Test
{
public static void main(String[] args)
{
Student stu1=new Student();
stu1.start();
Student stu2=new Student();
stu2.start();
Student stu3=new Student();
stu3.start();
Student stu4=new Student();
stu4.start();
//Person p=new Person();
//p.show();
}
}
//实现法:避免了单继承局限
class Person implements Runnable
{
private int y=100;
public void run()//重写Runnable中的run方法
{
while(true)
{
if(y>0)
System.out.println(Thread.currentThread().getName()+"-------"+y--);
}
}
}
class Test2
{
public static void main(String[] args)
{
Person p=new Person();