• 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

[SOLVED] Why do I get a compiler error referencing a static context ?

 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The following code snippet compiles and runs without any warnings or error messages. Notice that I'm invoking the go() method from a static context, but I'm invoking it on an instance of the Forty class. I see the difference now, but I'll complete my thought anyway.





class FortyOne doesn't compile or run because I'm referencing a non-static member of the FortyOne class inside a staic method of the FortyOne class. No need to respond. I see what's happening now. Thanks anyway -Harry




C:\TEMP>javac FortyOne.java
FortyOne.java:4: non-static method go(java.lang.Long) cannot be referenced from
a static context
story = go(343L);
^
1 error

 
reply
    Bookmark Topic Watch Topic
  • New Topic