• 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 reference

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Arg{
String []MyArg;
public static void main(String argv[]){
MyArg=argv;
}
public static void amethod(){
System.out.println(argv[1]);
}
}
in the above code the compiler starts reading line 3,4.....???
then what.what does line 4 try to say does it asks to jump to line 7 Please Explain in words.
how do u rectify the compilation error.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
public class Arg{
String []MyArg;
public static void main(String argv[]){
MyArg=argv; //1
}
public static void amethod(){
System.out.println(argv[1]);
}
}
Look closely at //1 , trying to acces non-static member of the class in a static method..which is not allowed. u have to create an instance fo Arg and change the statement as say
Arg a = new Arg();
a.MyArg = argv;

Thanks
Sanjeet
Plz let me know if anything is wrong
 
reply
    Bookmark Topic Watch Topic
  • New Topic