Semicolon is not mandatory in JSP method declaration. In fact I was thinking "Wouldn't semicolon cause a problem ? " :-) If there are 2 correct options then I think container must be ignoring the semicolon after declaration.
As Sudharsan said, you don't require a semicolon after a method declaration (option 2). The code within the curly braces would obviously require semicolons as per usual. I'm not sure why a semicolon is required in option 4 though? I can only assume that it is ignored by the JSP engine. As 2 options were required for the question, 2 and 4 are the best of the worst
posted 15 years ago
Method declarations need a semi-colon as a variable declaration do. But a method definition does'nt need a semicolon to terminate it. There is no concept of a variable definition though. . Also an extra semi-colon in your normal Java declaration/defintion statements would not affect the program syntax. It will just be ignored by the parser. you can try this
Dear all, Options 2 and 4 is correct. B'coz, 1. We can not define method in Scriplet (between <% and %> b'coz Scriplet code always goes to _jspService() method as it is. And java is not allowing us to define a method in one method it self. Where as, when we declare a variable or method between <%! and %> (JSP Declarations), it would be added to class which extends HttpJspBase class and not in a method. So, Options 1 and 5 r wrong. 2. Whereas Page directive is to inform Jsp Engine about page properties. And Directives r predefined so the option 3 is wrong. 3. Now, comes to 2nd and 4th option: 2nd is true b'coz it is the way how we define a java method in our class. (here it is a class who extends HttpJspBase class while translation) In the 4th option an additional ; is there, and we all know semicolon is mean to a complete statement in JAVA. Here in our example the semicolon would be added in a class which we can always do. Hope, i m clear enough. Best Regards, Dharmin [ January 28, 2003: Message edited by: Dharmin Desai ]
SCJP2 (93%),SCWCD(88%)<br />-------------------------------<br />Never under estimate yr self, just represent yr profile in proper manner.