Advertisement
apl-mhd

spring2017Problem 6

Jan 12th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package spring2017.problem6;
  2.  
  3. import one172.ThreadErrorList5;
  4.  
  5. public class TestThread1 implements Runnable{
  6. //problem a
  7.     Thread t;
  8.     TestThread1(){
  9.  
  10.     }
  11.  
  12.  
  13.  
  14.     String name;
  15.     public TestThread1(String name) {
  16.         this.name = name;
  17.  
  18.         t = new Thread(this);
  19.     }
  20.     public void run(int n){
  21.         System.out.printf("Running:%s %d times.\n", name, n);
  22.     }
  23.  
  24.     public  void run(){
  25.  
  26.         System.out.println("bangladehs");
  27.  
  28.     }
  29.  
  30.  
  31.     public static void main(String[] args) {
  32.  
  33.         TestThread1 t = new TestThread1();
  34.  
  35.  
  36.         TestThread1 t1 = new TestThread1("First Thread");
  37.         t1.t.start();
  38.  
  39.         try {
  40.  
  41.             t1.t.join();
  42.         }
  43.         catch (Exception e){}
  44.  
  45.     }
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. package spring2017.problem6;
  57.  
  58. import java.io.IOException;
  59. public class TestExceptionError {
  60.     public static void main(String[] args) {
  61.  
  62.  
  63.  
  64.  
  65.         //System.out.println("aa");
  66.  
  67.         try {
  68.             whoIs("IOException");
  69.         }
  70.  
  71.         catch (IOException e) {
  72.             e.printStackTrace();
  73.         }
  74.  
  75.         catch (Exception e) {
  76.             e.printStackTrace();
  77.         }
  78.  
  79.         finally{
  80.             System.out.println("Always executes.");
  81.         }
  82.         System.out.println("Which exception should be handled?");
  83.  
  84.     }
  85.     public static void whoIs(String n) throws IOException{
  86.         System.out.println("Who is "+n+"?");
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement