Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question Bank ID : 41

 
Sar Lolla
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.
 
Mikalai Zaikin
Ranch Hand
Posts: 3381
12
  • 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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!