标签:
2016-07-01
package com.java1995; /** * 打印机类 * @author Administrator * */ public class Print { /** * * @param name 学生姓名 * @param eScore 英语成绩 * @param mScore 数学成绩 * @param yScore 语文成绩 */ public void printScore(String name,int eScore,int mScore,int yScore){ System.out.println(name+"的英语成绩:"+eScore); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(name+"的数学成绩:"+mScore); System.out.println(name+"的语文成绩:"+yScore); } }
package com.java1995; /** * 老师类 * @author Administrator * */ public class Teacher implements Runnable{ //封装 private Print p; private String name; private int eScore,mScore,yScore; public Teacher(Print p,String name,int eScore,int mScore,int yScore){ this.p=p; this.name=name; this.eScore=eScore; this.mScore=mScore; this.yScore=yScore; } //封装的实现 public Print getP() { return p; } public void setP(Print p) { this.p = p; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int geteScore() { return eScore; } public void seteScore(int eScore) { this.eScore = eScore; } public int getmScore() { return mScore; } public void setmScore(int mScore) { this.mScore = mScore; } public int getyScore() { return yScore; } public void setyScore(int yScore) { this.yScore = yScore; } //重写run()方法 @Override public void run() { // TODO Auto-generated method stub p.printScore(name, eScore, mScore, yScore); } }
package com.java1995; public class Test { public static void main(String[] args) { Print p=new Print(); Teacher t1=new Teacher(p,"博尔特",10,11,12); Teacher t2=new Teacher(p,"加特林",23,56,1); Teacher t3=new Teacher(p,"苏炳添",34,55,90); Thread th1=new Thread(t1); Thread th2=new Thread(t2); Thread th3=new Thread(t3); th1.start(); th2.start(); th3.start(); } }
标签:
原文地址:http://www.cnblogs.com/cenliang/p/5634271.html