Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public class TwoThreads {
  2. /* public static class Thread1 extends Thread {
  3. public void run() {
  4. System.out.println("A");
  5. System.out.println("B");
  6. }
  7. }
  8.  
  9. public static class Thread2 extends Thread {
  10. public void run() {
  11. System.out.println("1");
  12. System.out.println("2");
  13. }
  14. } */
  15.  
  16. public static class ThreadAB implements Runnable{
  17.  
  18. Thread t;
  19. String s1;
  20. String s2;
  21.  
  22. public ThreadAB(String string1, String string2) {
  23. // TODO Auto-generated constructor stub
  24. s1=string1;
  25. s2=string2;
  26. }
  27.  
  28. @Override
  29. public void run(){
  30.  
  31. System.out.println(s1);
  32. System.out.println(s2);
  33.  
  34. }
  35.  
  36. public void start()
  37. {
  38. run();
  39. }
  40. }
  41.  
  42. public static void main(String[] args) {
  43.  
  44. new ThreadAB("A","B").start();
  45. new ThreadAB("1","2").start();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement