Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. public class Solution {
  2. public static void main(String[] args) throws InterruptedException {
  3. Mouse alpha = new Mouse("#1");
  4.  
  5. Mouse mouse1 = new Mouse("#2");
  6.  
  7. Mouse mouse2 = new Mouse("#3");
  8.  
  9. }
  10.  
  11. private static void eat() {
  12. try {
  13. Thread.sleep(2000);
  14. } catch (InterruptedException e) {
  15. }
  16. }
  17.  
  18. public static class Mouse extends Thread {
  19. public Mouse(String name) {
  20. super(name);
  21. start();
  22. }
  23.  
  24. public void run() {
  25. System.out.println(getName() + " is starting to eat");
  26.  
  27. System.out.println(getName() + " has finished eating");
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement