public class Zuoye {
public static void main(String[] args) throws Exception {
FileOutputStream fos=new FileOutputStream("x.student");
ObjectOutputStream oos=new ObjectOutputStream(fos);
List<Student>list=new ArrayList<>();
Student s1=new Student("哈哈",1111,22,99);
Student s2=new Student("嘻嘻",2222,23,98);
Student s3=new Student("只在",3333,24,97);
Student s4=new Student("汪汪",4444,25,96);
list.add(s1);
list.add(s2);
list.add(s3);
list.add(s4);
oos.writeObject(list);
FileInputStream fis=new FileInputStream("x.student");
ObjectInputStream ois=new ObjectInputStream(fis);
Object o=ois.readObject();
if (o instanceof List) {
List list1 = (List) o;
System.out.println(list1);
}
ois.close();
oos.close();
}
}
public class Zuoye01 extends Thread{
@Override
public void run() {
System.out.println("继承类实现线程");
for (int i = 0; i < 10; i++) {
System.out.println(this.getName()+":"+i);
}
}
public Zuoye01() {
}
public Zuoye01(String name) {
super(name);
}
}
public static void main(String[] args) {
Zuoye01 t1=new Zuoye01("哈哈");
Zuoye01 t2=new Zuoye01("xx");
t1.start();
t2.start();
}
public class Zuoye02 implements Runnable{
@Override
public void run() {
System.out.println("接口类实现线程");
for (int i = 0; i < 10; i++) {
System.out.println(Thread.currentThread().getName()+":"+i);
}
}
}
public static void main(String[] args) {
Zuoye02 t4=new Zuoye02();
Zuoye02 t5=new Zuoye02();
Thread xx=new Thread(t4,"hh");
Thread yy=new Thread(t5,"ww");
xx.start();
yy.start();
}
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 20; i++) {
System.out.println(Thread.currentThread().getName()+i);
}
}
}).start();