This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I am sorry. Test say 3 and 4. Can you lock this topic.
vinay jain
Greenhorn
Joined: Nov 07, 2001
Posts: 27
posted
0
The Answers should be 3 and 4, since a try block can not stand on its own e.g. If you have <pre> try { // do something } ... </pre> and there is no catch or finally block then it is an error.
Madan, Gopal
Ranch Hand
Joined: Aug 13, 2001
Posts: 86
posted
0
Can somebody explain why option 1 is not true!!??
1. For each try block there must be at least one catch block defined.
I thought this is valid!!
[This message has been edited by Madan, Gopal (edited November 07, 2001).]
Salamina Daniel
Ranch Hand
Joined: Oct 10, 2001
Posts: 41
posted
0
The reason is obvious, Madan. You can have a try - finally block whitout any catch involved and Java Language Specification -14.19 gives this description TryStatement: try Block Catches try Block Catches-opt! Finally So, as you can see the catch block is optional ! Example: import java.io.*; public class ATest{ public static void main(String arg[]) throws IOException{ try{ FileInputStream f=new FileInputStream("c:\test.txt"); } finally{ System.out.println("No catch block"); } } } Therefore answer 1.(For each try block there must be at least one catch block defined.) is wrong ! Best regards
[This message has been edited by Salamina Daniel (edited November 07, 2001).]