• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mocke exam question

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c would be true as
<% private int a=100; %>
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Axel Janssen:
c would be true as
<% private int a=100; %>


Why?
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]

 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic