Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Static fields and arrays

807597Jun 28 2005 — edited Jun 28 2005
I'm putting together my first 'structure' that I want to use as an array. Currently the structure (or should I be saying class?) will only be holding variables. It looks like below:

package weather;

public class WeatherObject
{
public WeatherObject(){}

// Date and Time
static String datLastUpdate = "N/A";
static String datDay = "";
static String datDate = "";
static String datMonth = "";
}

However when I try to access it with the code below:

WeatherObject[] wo = new WeatherObject[10];
int n = 0;
wo[n].datLastUpdate ="x";

I get the following warnings:

The static field WeatherObject.datLastUpdate should be accessed in a static way

I've tried removing 'static', but that just crashed the program. Can anyone tell me what I'm doing wrong. The program works OK with the warnings there, but in the past warnings I've ignored have always come back to bite me.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2005
Added on Jun 28 2005
4 comments
93 views