• 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

Usage of final keyword

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Here is a code snippet which I experimented with by compiling and executing. I would like to know if everyone is getting the same result.
What is the expected behavior of the following piece of code?

a) Compiler-time error
b) Code runs and prints the following
final sl=0
c) Code runs and prints the following
final sl=
d) None of the above
By just looking at the code, I thought it might be (a) but the answer turned out to be (c).
Perhaps someone could shed some light on this type of behavior. I checked the JLS but it didn't cover this scenario.
Thanks.
-Sharmila
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a close look at the System.out.println statement.
It is:
System.out.println("final sl=");
and NOT
System.out.println("final sl=" + sl);
Also, try coding the example and check it out,
Brian
[ April 11, 2002: Message edited by: Brian Lugo ]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah.. this isn't a very fair question
 
Sharon Miller
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
My mistake. I should have paid attention to my own code.
Thanks.
-Sharmila
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic