• 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

static variable in main

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#) lass wrapper
{
public static void main(String [] str)
{
static int l; // 1
Integer I = new Integer(6);

System.out.println(I);
System.out.println(l);
}
}

what is wrong withh this code if i removw line 1 then its all OK
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by devesh singh:
#) lass wrapper
{
public static void main(String [] str)
{
static int l; // 1
Integer I = new Integer(6);

System.out.println(I);
System.out.println(l);
}
}

what is wrong withh this code if i removw line 1 then its all OK



Hi Devesh,
int l is a local variable to main(). Local variable cannot have any access modifier. If you remove 'static' declaration from int l, you will be okay. BTW, Don't forget to initialize l.
- Lam -

[This message has been edited by Lam Thai (edited May 14, 2001).]
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by devesh singh:
#) lass wrapper
{
public static void main(String [] str)
{
static int l; // 1
Integer I = new Integer(6);

System.out.println(I);
System.out.println(l);
}
}

what is wrong withh this code if i removw line 1 then its all OK


==============================
I think you expect(your question is obscure!) the answer below:
Local (methods) variables cannot be declared static - your compiler will show anger!
 
money grubbing section goes here:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic