This week's book giveaway is in the Security forum.
We're giving away four copies of Securing DevOps and have Julien Vehent on-line!
See this thread for details.
Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question Bank ID : 41  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following statements are TRUE (Choose 2).

1) <%! int i; %> is a variable declaration that has object scope within
the servlet.


2) <% int i; %> is a variable declaration that is class scope to the service method.


3) <%! int i; > a variable declaration that has local scope within the
service method of the servlet

4) <% int i = 0; %> is a variable declaration that has local scope within the service method of the servlet.

The mock test is giving the answers as 1 and 4. Why? what is the meaning of object scope?

Can some one please help me? I marked 2 and 4 as answers.
 
Ranch Hand
Posts: 3440
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy

1)



will be converted at JSP translation time to:



which is object scope (global scope)


4)



will be converted at JSP translation time to:



which is local scope (method scope)

NOTE, you can have both :


and


in the same JSP - one variable will shadow another

regards,
MZ
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!