Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mocke exam question

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%! private int a=100; %> is which of the following?
A A declaration
B A scriptlet
C A variable that is only visible to a single client
D A variable that is accessible to multiple clients
according to me correct answer is
A but second correct ans shud be C or D
i think it shud by C
can anyone correct me if i m wrong
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a JSP get compiled into a servlet the declaration part will be placed outside the service method but within the class. In this case the variable will become instance variable & therefore accessible to all clients.
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
c would be true as
<% private int a=100; %>
 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Axel Janssen:
c would be true as
<% private int a=100; %>

Why?
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rick collette:

Why?

Ans C : A variable that is only visible to a single client

when you declare like :
<% private int a=100; %>
then in servlet it will declared inside service() method hence every client will have its own copy.

NO NO I am wrong. you can not have varible which is visible to single client.
OR here single means individual client.
Correct me if I am wrong.
TIA
[ April 24, 2002: Message edited by: Ravish Kumar ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing like visible to single client.
if declared in scriplet then each thread has its own variable ie it is a local variable. so it should not be a problem in distributed environment
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C is wrong. Any variable declared within the declaration will become instance variable.That variable can be accessed to all clients becoz it is not a method variable .. The "private" just indicates the visibilty of the variable.. Declaring the variable as private,public or protected hardly makes any difference ..becoz we do not create subclass or create any instance of the servlet compiled from JSP.
Originally posted by Ravish Kumar:

Ans C : A variable that is only visible to a single client

when you declare like :
<% private int a=100; %>
then in servlet it will declared inside service() method hence every client will have its own copy.

NO NO I am wrong. you can not have varible which is visible to single client.
OR here single means individual client.
Correct me if I am wrong.
TIA
[ April 24, 2002: Message edited by: Ravish Kumar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic