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

static final array

Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
Can arrays be static and final?
Mahesh Bhatt
Ranch Hand

Joined: Sep 15, 2004
Posts: 88
Hi Miki,

I see no problems there. You can definately declare an array as final and static both.

If you are having a problem somewhere in a program, I guess it might be because you are either declaring the array inside a static context, or may be you are trying to change the reference of this array .

I am writing a code here :


This will give you a compilation error because you are trying to change the reference value of the array that has been declared as "final". This is illegal.

however, in the following code :




there is no problem here. This code compiles and prints the output :



so, the moral of the story is : "when you declare an array as final, you can change the elements in the array, however you cannot change the reference of this array."

Hope it helps you

All the best


Impossible is I M Possible
Rahul Bajaj
Ranch Hand

Joined: Sep 21, 2004
Posts: 45
Thank You for your reply.It cleared my confusion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static final array