• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic