This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

non static referenced from a static context?

 
Brad Wong
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing a program to calculate interest with a separate method for the calculation, but it won't compile...any help?

 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48409
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I like that classification system! Sort of a Meyers-Briggs for methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic