• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt marcus mock exam question

 
Bhupendra Khabrani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can anybody explain me the answer of following question:

<%request.setAttribute("Two","2");
Integer One = new Integer(1);%>

${One + 1}
${Two}
${Two + 1}

the answer in mock given is 123.
i think ${One + 1} will output '2' becoz the value of One variable is coerced and added to numeral 1.
pls correct me if wrong!!
thanks
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'One' is not added in any scope
 
Sandip Kaviman
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is equivalent to

 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sandip Kaviman:
The code is equivalent to



 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhupendra Khabrani, what happened when you compiled and ran the code?
Marcus
 
Bhupendra Khabrani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everyone,
i got the reply when i ran the code ..
i get 1 2 3 as result

this is becoz since the One in not there in any scope so EL treats it as 0 zero hence 0+1=1. correct me if i am wrong Marcus.

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic