Win a copy of Design for the Mind this week in the Design 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: 2985
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: 48652
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: 2985
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