You are on page 1of 17

1 a) class Demo{ public static void main(String[] args){ try { int a=10; int c=a/0; System.out.

println(c); } catch (ArithmeticException ex) { System.out.println("Runtime Error"); System.out.println(a); } } } 1 b) class Demo{ public static void main(String[] args){ try { int a=10; int c=a/0; System.out.println(c); } catch (ArithmeticException ex) { System.out.println("Runtime Error"); } } } 2 a) class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; } catch (ArithmeticException ex){ System.out.println("2"); } System.out.println("3"); } } 2 b) class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; } catch (Exception ex){ System.out.println("2"); }

System.out.println("3"); } } 3)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; } catch(ArrayIndexOutOfBoundsException ex) { System.out.println("2"); } try{ System.out.println("3"); int a=10/0; System.out.println("4"); } catch (ArithmeticException ex){ System.out.println("5"); } System.out.println("6"); } } 4)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; } catch(NullPointerException ex) { System.out.println("2"); } try{ System.out.println("3"); int a=10/0; System.out.println("4"); } catch (ArithmeticException ex){ System.out.println("5"); } System.out.println("6"); } } 5)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; } catch(NullPointerException e) { System.out.println("2"); throw e; } try{

System.out.println("3"); int a=10/0; System.out.println("4"); } catch (ArithmeticException ex){ System.out.println("5"); } System.out.println("6"); } } 6)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; } catch(ArrayIndexOutOfBoundsException e) { System.out.println("2"); throw e; } try{ System.out.println("3"); int a=10/0; System.out.println("4"); } catch (ArithmeticException ex){ System.out.println("5"); } System.out.println("6"); } } 7)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ } catch(ArrayIndexOutOfBoundsException e) { System.out.println("2"); throw e; } try{ System.out.println("3"); int a=10/0; System.out.println("4"); } catch (ArithmeticException ex){ System.out.println("5"); } System.out.println("6"); } } 8)class Demo{ public static void main(String[] args){ System.out.println("1"); try{

int[] arr={10,20}; arr[2]=30; } catch (ArithmeticException e){ System.out.println("2"); } catch (Exception e){ System.out.println("3"); } catch (ArithmeticException ex){ System.out.println("4"); } System.out.println("5"); } } 9)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; } catch (ArithmeticException e){ System.out.println("2"); } catch (Exception e){ System.out.println("3"); } catch (ArrayIndexOutOfBoundsException ex){ System.out.println("4"); } System.out.println("5"); } } 10)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; } catch (ArithmeticException e){ System.out.println("2"); } catch (ArrayIndexOutOfBoundsException ex){ System.out.println("4"); } catch (Exception e){ System.out.println("3"); } System.out.println("5"); } } 11)class Demo{ public static void main(String[] args){ System.out.println("1"); try{

int[] arr={10,20}; int a=arr[2]/0; } catch (ArithmeticException e){ System.out.println("2"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("3"); } catch (Exception ex){ System.out.println("4"); } System.out.println("5"); } } 12)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; System.out.println("2"); try{ arr[0]=0; arr[1]/=arr[0] } catch (ArrayIndexOutOfBoundsException e){ System.out.println("4"); } } catch (ArithmeticException e){ System.out.println("5"); } System.out.println("6"); } } 13)class Demo{ public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; System.out.println("2"); try{ arr[0]=1; arr[arr[1]]/=0; arr[1]/=arr[0]; } catch (ArrayIndexOutOfBoundsException e){ System.out.println("4"); } System.out.println("5"); } catch (ArithmeticException e){ System.out.println("6"); } } } 14)class Demo{

System.out.println("3");

System.out.println("3");

public static void main(String[] args){ System.out.println("1"); try{ int[] arr={10,20}; arr[2]=30; System.out.println("2"); try{ arr[1]/=arr[0]; rintln("3"); } catch (ArrayIndexOutOfBoundsException e){ System.out.println("4"); } System.out.println("5"); } catch (ArithmeticException e){ System.out.println("6"); } } } 15) class Demo{ static String s="-"; public static void main(String[] args){ s+="1"; try{ String s1="hello"; s1=null; s1.concat("hi"); try{ } catch (NullPointerException e){ s+="2"; } s+="3"; } catch (NullPointerException e){ s+="4"; } System.out.println(s); } } 16) class Demo{ static String s="-"; public static void main(String[] args){ s+="1"; try{ String s1="hello"; s1=null; try { s1.concat("hi"); } catch (NullPointerException e) { s+="2"; } s+="3"; }

System.out.p

catch (NullPointerException e) { s+="4"; } System.out.println(s); } } 17) class Demo{ static String s="-"; public static void main(String[] args){ s+="w"; try{ try { throw new Exception(); } catch (Exception e) { s+="p"; try { throw e; } catch (Exception e) { s+="x"; } s+="a"; } s+="c"; } catch (Exception e){ s+="d"; } System.out.println(s); } } 18) class Demo{ static String s="-"; public static void main(String[] args){ s+="w"; try{ try{ throw new Exception(); } catch (Exception e){ s+="p"; try{ throw e; } catch (Exception e1){ s+="x"; throw e1; } s+="a"; } s+="c";

} catch (Exception e){ s+="d"; } System.out.println(s); } } 19) class Demo{ static String s="-"; public static void main(String[] args){ s+="w"; try{ try{ throw new Exception(); } catch (Exception e){ s+="p"; try{ throw e; } catch (Exception e1){ s+="x"; throw e1; } finally{ s+="a"; } } finally{ s+="c"; } } catch (Exception e){ s+="d"; } System.out.println(s); } } 20) class Demo{ static String s="-"; public static void main(String[] args){ s+="w"; try{ try{ throw new Exception(); } catch (Exception e){ s+="p"; } finally{ s+="x"; } s+="a"; } catch (Exception e1){ s+="c";

} finally{ System.out.println(s); } } 21) class Demo{ static String s="-"; public static void main(String[] args){ s+="w"; try{ throw new Exception(); try{ throw new Exception(); } catch (Exception e){ s+="p"; } finally{ s+="x"; } s+="a"; } catch (Exception e1){ s+="c"; } finally{ System.out.println(s); } } 22) import java.io.IOException; class Demo{ public static void show(int i){ if(i==0) throw new IOException(); else System.out.println(i); } public static void main(String[] args){ try{ show(1); } catch (IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 23) import java.io.IOException; class Demo{ public static void show(int i){ try{ if(i==0) throw new IOException(); else System.out.println(i); }

catch (Exception e){ System.out.println("hi"); } } public static void main(String[] args){ try{ show(1); } catch (IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 24) import java.io.IOException; class Demo{ public static void show(int i){ try{ if(i==0) throw new IOException(); else System.out.println(i); } catch (Exception e){ System.out.println("hi"); } } public static void main(String[] args){ try{ show(0); } catch (IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 25) import java.io.IOException; class Demo{ public static void show(int i) throws IOException{ try{ if(i==0) throw new IOException(); else System.out.println(i); } catch (Exception e){ System.out.println("hi"); } } public static void main(String[] args){ try{ show(0); }

catch (IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 26) import java.io.IOException; class Demo{ public static void show(int i) throws IOException{ try{ if(i==0) throw new IOException(); else System.out.println(i); } catch (Exception e){ System.out.println("hi"); throw e; } } public static void main(String[] args){ try{ show(0); } catch (IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 27) import java.io.IOException; class Demo{ public static void show(int i)throws IOException{ if(i==0) throw new Exception(); else System.out.println(i); } public static void main(String[] args){ show(0); System.out.println("welcome"); } } 28) import java.io.IOException; class Demo{ public static void show(int i)throws IOException{ if(i==0) throw new Exception(); else System.out.println(i); }

public static void main(String[] args){ try{ show(0); } catch(ArithmeticException e){ System.out.println("hello"); } System.out.println("welcome"); } } 29) import java.io.IOException; class Demo{ public static void show(int i) throws ArithmeticException { if(i==0) throw new Exception(); else System.out.println(i); } public static void main(String[] args){ try{ show(0); } catch(ArithmeticException e){ System.out.println("hello"); } System.out.println("welcome"); } } 30) import java.io.IOException; class Demo{ public static void show(int i) throws ArithmeticException { if(i==0) throw new Exception(); else System.out.println(i); } public static void main(String[] args){ try{ show(0); } catch( IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 31) import java.io.IOException; class Demo{

public static void show(int i)throws Exception { if(i==0) throw new Exception(); else System.out.println(i); } public static void main(String[] args){ try{ show(0); } catch( IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 32) import java.io.IOException; class Demo{ public static void show(int i)throws IOException { if(i==0) throw new Exception(); else System.out.println(i); } public static void main(String[] args){ try{ show(0); } catch( IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 33) import java.io.IOException; class Demo{ public static void show(int i) throws IOException,InterruptedException { if(i==0) throw new IOException(); else System.out.println(i); } public static void main(String[] args){ try{ show(0); } catch( IOException e){ System.out.println("hello"); }

System.out.println("welcome"); } } 34) import java.io.IOException; class Demo{ public static void show(int i) throws IOException,InterruptedException{ throw new IOException(); } public static void main(String[] args){ try{ show(0); } catch(IOException e){ System.out.println("hello"); } System.out.println("welcome"); } } 35) import java.io.IOException; class A{ public void show()throws IOException{ System.out.println("A"); } } class B extends A{ public void show()throws IOException{ System.out.println("B"); } } 36) import java.io.IOException; class A{ public void show()throws IOException{ System.out.println("A"); } } class B extends A{ public void show() { System.out.println("B"); } } 37) import java.io.IOException; class A{ public void show()throws IOException{ System.out.println("A"); } } class B extends A{ public void show() throws ArithmeticException { System.out.println("B"); }

} 38) import java.io.IOException; class A{ public void show()throws IOException{ System.out.println("A"); } } class B extends A{ public void show() throws FileNotFoundException{ System.out.println("B"); } } 39) import java.io.IOException; class A{ public void show()throws IOException{ System.out.println("A"); } } class B extends A{ public void show() throws Exception { System.out.println("B"); } } 40) import java.io.IOException; class A{ public void show()throws IOException{ System.out.println("A"); } } class B extends A{ public void show() throws InterruptedException { System.out.println("B"); } } 41) import java.io.IOException; class A{ public void show()throws IOException{ System.out.println("A"); } } class B extends A{ public void show() { super.show(); System.out.println("B"); } } 42) import java.io.IOException; class A{ public void show()throws IOException{

System.out.println("A"); } } class B extends A{ public void show() throws IOException,ArithmeticException super.show(); System.out.println("B"); } } 43) class Demo{ public static int show(int a){ try{ System.out.println("hello"); return a+10; } catch (Exception e){ System.out.println("hi"); } } {

public static void main(String[] args){ int b=show(10); System.out.println(b); } } 44) class Demo{ public static int show(int a){ try{ System.out.println("hello"); return a+10; } finally{ System.out.println("hi"); } }

public static void main(String[] args){ int b=show(10); System.out.println(b); } } 45)class Demo{ public static int show(int a)throws Exception{ try{ System.out.println("hello"); int c=10/0; return a+10; } finally{

System.out.println("hi"); } } public static void main(String[] args) { try{ int b=show(10); System.out.println(b); } catch (Exception ex){ System.out.println("exception"); } } }

You might also like