• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP fragments correctly define a method  RSS feed

 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the follwing JSP fragments correctly define a method?

1.
<% public void m1() { ... } %>

2.
<%! public void m1() { ... } %>

3.
<%@ public void m1() { ... } %>

4.
<%! public void m1() { ... }; %>

5.
<% public void m1() { ... }; %>

otions:
1
2
3
4
5

i answer 1,2 but the right answer :2,4


Any explanations?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to remember that everything you put in a scriptlet will go into a method. So you cannot define a new function in scriptlets, you have to use declarations instead. Therefore, both 1 and 5 can be discarded.
 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification
 
Jan van Mansum
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange, I thought option 4 was incorrect, because of the final semicolon, but it compiles alright. How does this fit into Java syntax? Is it something like an "empty field definition"?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!