Originally Posted by
bengregg
So I'm trying to figure out how to create Arrays out of Objects but I'm having a problem adding an Object to an Array.
Here's what I have:
public class Main {
double[] values = new double[10];
double[] morevalues = {2,3,4,5};
double morevaluesone= morevalues[1];
Coin Bank[] = new Coin[3];
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Coin quarter = new Coin("Quarter", .25);
Bank[0]=quarter;
I get the error at Bank[0]=quarter;
(non-static variable Bank cannot be referenced from a static context)
What am I doing wrong?
Here is my coin class:
public class Coin {
String name;
double value;
public Coin (String aname, double avalue)
{
name=aname;
value=avalue;
}
}
The non static variable “Bank” is trying to use in static method (main). To resolve the error you would require to modify “Bank” as static.