aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 2771
    
  10

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: 36579
    
  16
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: 2771
    
  10

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
extra credit in class but stuck on persentage rates
Use of Math.pow?
Loop problems
static method data validation in a dialog box app
Explanation