• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

please explain 'static'

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class example
{
public static void main(String args[])
{
static int h = 8;
System.out.println(h);
}
}
When I compile this program, it gives an comilation error:
Statement expected : static int h = 8;
Identifier expected: System.out.println(h);
Can anyone please explain this?
Thankx
Shilpa Jain
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shilpa,
You cannot assign the static modifier and access permissions like private, protected, public etc. to variables within a local method. These are applicable only to class variables.
If you want to print h which is defined within the static method main(), you need not declare h as static. A simple 'int h =0;' will do.
Regds
Sathish
 
Shilpa Jain
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Satish
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish,
Thanks for the reply.. You seem to be having all Java basics and fundamentals on your finger tips man..
Can you suggest some books and advices so that i too can become confident and good in Java
Cheers
Venu
 
Hang a left on main. Then read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic