• 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

help me on output of this code

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello dear friends ,
i have a problem on this programe...
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the question??

Rob
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Tahir"
Please edit your profile and change your Display Name so that it complies with the JavaRanch Naming Policy. Judging from what's in your profile, I suggest you try changing your display name to "Muhammad Tahir".
Thanks for your cooperation!
Junilu
 
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 Rob Ross:
What is the question??

Rob


agree with Rob
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
final variables need to be initalized somewhere in your code.
in this case u dont initalize the final int x
and thats why it gives u an exception.
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tahir!
The code that you have written is not correct.
You are missing the class declaration statement and the opening parenthesis that goes with it.
Re-write the code as:

Okay, now lets take a look at the problem.
"x" is declared is final instance constant, hence it must be assigned a value in an initializer, or in every constructor.
So, try initializing x in either instance initializer or in the constructor before you try to access "x" in the System.out.println statement.
I hope this helps.
Oh! One more thing that I forgot to mention is you cannot declare variables outside the class/interface body. Sorry no C/C++ tricks to declare/initialize global constants before the class declaration. It does not work in Java.
[ February 07, 2002: Message edited by: Brian Lugo ]
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic