Home > Java Programming > Exceptions > Questions and Answers
01. |
class A{ public static void main(String args[]){ try{ System.out.println(“oneâ€); }catch(Exception e){
System.out.println(“twoâ€); } finally{ System.out.println(“threeâ€); } } } | |||||||||||
|
02. |
class A{ public static void main(String args[]){ try{ System.out.println(“oneâ€); System.exit(0); }catch(Exception e){ System.out.println(“twoâ€); } finally{ System.out.println(“threeâ€); }
} } | |||||||||||
|
03. |
class A{ public static void main(String args[]){ try{ System.out.println(“oneâ€); }
} Output? | |||||||||||
|
04. |
class A{ void display() throws IOException,FileNotFoundException { System.out.println(“class Aâ€); } } class B extends A { void display() throws IOException, FileNotFoundException,NullPointerException { System.out.println(“class Bâ€); } } class Test { Public static void main(String args[]){ B b=new B(); b.display(); } } Output? | |||||||||||
|
05. |
class A{ void display() throws IOException,FileNotFoundException { System.out.println(“class Aâ€); } } class B extends A { void display() throws ClassNotFoundException, SQLException { System.out.println(“class Bâ€); } } class Test { Public static void main(String args[]){ B b=new B(); b.display(); }
} Output? | |||||||||||
|
06. |
Given a valid DateFormat object named df, and 1. Date d = new Date(0L); 2. String ds = "December 15, 2004"; 3. // insert code here What updates d's value with the date represented by ds? | |||||||||||
|
07. |
Given: public static void parse(String str) { try { float f = Float.parseFloat(str); } catch (NumberFormatException nfe) { f = 0; } finally { System.out.println(f); } } public static void main(String[] args) { parse("invalid"); } What is the result?
| |||||||||||
|
08. |
Given: 1. class A { 2. public void process() { System.out.print("A,"); }} 3. class B extends A { 4. public void process() throws IOException { 5. super.process(); 6. System.out.print("B,"); 7. throw new IOException(); 8.} 9. public static void main(String[] args) { 10. try { new B().process(); } 11. catch (IOException e) { System.out.println("Exception"); }}} What is the result? | |||||||||||||||
|
09. |
1 class TestException extends Exception { } 2 class A { 3 public String sayHello(String name) throws TestException { 4 if(name == null) throw new TestException(); 5 return "Hello " + name; } 6 } 7 public class TestA { 8 public static void main(String[] args) { 9 new A().sayHello("Aiko"); 10 } } | |||||||||||
|
10. |
class A{ static void test() { try { String x = null; System.out.print(x.toString() + " "); }finally { System.out.print("finally ");
} } public static void main(String[] args) { try { test(); } catch (Exception ex) { System.out.print("exception "); } } } What is the result? | |||||||||||||||
|