my dog learned polymorphism
The moose likes Beginning Java and the fly likes field declaration question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "field declaration question" Watch "field declaration question" New topic

field declaration question

Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Could anyone explain what the Month2 variable looks like. Also
what does the month array look like?
I thought the Month2 variable was an object of several objects namely JAN, FEB AND MARCH, but when a reference is made with m it refers to one of the objects, JAN.
Also, what does month look like. I thought it would be an array called month where each element contains a month2 object. Something like:
month 0 JAN refers to new Month2("January")
1 FEB refers to new Month2("February")
2 MAR refers to new Month2("March")
Thank you in advance,

(edited by Cindy to format code)
[This message has been edited by Cindy Glass (edited May 07, 2001).]
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
The month variable is an array of Month2's.
The JAN variable is a variable of type Month2 that holds a string "January";
Same for FEB and MAR.
These 3 are in addition to the month array, and were passed to the array when creating it.
Because they declared the 3 Month2 variables in line it is harder to see off the bat, but it is the same as saying
public final static Month2 JAN = new Month2("January");
public final static Month2 FEB = new Month2("February");
public final static Month2 MAR = new Month2("March");
So since there are 4 variables, you can refer to any one of them.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: field declaration question
It's not a secret anymore!