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

Any body can help ? Thank you

 
muthu moorthy
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following jsp code:



<html>
<body>
<% String a = "aaa"; %>
<%! String a = "AAA"; %>
<% String b = "bbb"; %>
<%! String b = "BBB"; %>
<% out.println(a+b); %>
</body>
</html>



What will be the output?



Options

Select 1 correct option.

A. aaabbb

B. aaaBBB

C. AAAbbb

D. AAABBB

E. Compilation error!
 
Kamesh Rao
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option 1 is the correct one.
 
muthu moorthy
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there are two variables in the same name (local and instance), will take always local variable, is it so ?

Kindly explain. thank you
 
Kamesh Rao
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you declare a variable in a declarative tag these are created as class level variables (available to all the methods of the class). If you declare variables in a scriplet it is created in the service method of the generated servlet class.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there are two variables in the same name (local and instance), will take always local variable, is it so ?

It's just basic java....I don't find any reason for any confusion here unless you're getting confused with plain old java concepts itself.
[ January 10, 2007: Message edited by: Sayak Banerjee ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic