Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFS Doubt

 
Ramesh NarayananPerumal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new for JavaRanch and preparing SCWCD.Pl clarify my doubts.
In Page 293:
<! int doubleCount(){
count = count*2;
return count %>
<! int count=1; %>

It is ok because java accepts forward referncing.

but in case of scriplet in page 300
<% int y = 5 + x; %>
<% int x = 2; %>
They mentioned this won't complie. Why it will not compile?

Ramesh.N
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declaration of new variables into <%! %> will define the variable as class members. So you can refer to "count" into the "doubleCount" function.

However, declarations of new variable into scriplets (<% %> will define+ the variable locally. So you cannot reference x, as long as it has not been declared.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic