This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes non static referenced from a static context? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "non static referenced from a static context?" Watch "non static referenced from a static context?" New topic
Author

non static referenced from a static context?

Brad Wong
Greenhorn

Joined: Jan 04, 2013
Posts: 1
Writing a program to calculate interest with a separate method for the calculation, but it won't compile...any help?

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2841
    
  11

First, please UseCodeTags.

No, first, welcome to JavaRanch!

Second, please UseCodeTags.

Now, you can't reference non-statics from statics. Either declare your method static, or create an instance of your class and use that to call the method.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
That is not simple interest you are calculating, but compound interest. If you find the most dubious classification of methods known to modern science, that comes to be a 1368. You could therefore consider making it static.
Note you can’t override static methods, nor make interface methods static.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2841
    
  11

Hey, I like that classification system! Sort of a Meyers-Briggs for methods.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: non static referenced from a static context?
 
Similar Threads
static method data validation in a dialog box app
Use of Math.pow?
Explanation
extra credit in class but stuck on persentage rates
Loop problems