943,740 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2591
  • Java RSS
Aug 10th, 2004
1

Any chance of a little help?

Expand Post »
The following code will not compile n i'm a little stuck as to why -

public class Question8{

static final int ROW_SIZE = 10;
static final int COL_SIZE;

public static void main(String[] args){
COL_SIZE = 10;
ROW_SIZE = ROW_SIZE + 10;
}
}
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
steventhms is offline Offline
1 posts
since Aug 2004
Aug 10th, 2004
1

Re: Any chance of a little help?

I'm not sure. I was able to compile without any errors.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
scordle725 is offline Offline
4 posts
since Aug 2004
Aug 10th, 2004
0

Re: Any chance of a little help?

static final int ROW_SIZE = 10;
static final int COL_SIZE;

You are declaring ROW_SIZE AND COL_SIZE as final ....
when a variable is declared as final ... its value cant be changed at any stage of the program. And you are changing the values of both .. so it wont compile.
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Aug 10th, 2004
0

Re: Any chance of a little help?

yeah . . .

what nanosani said. When you declare a variable as a final, that variable cannot be changed - ever (well until the garbage collector comes to get it).

You must give a value to a final variable when you declare it. Otherwise, you cannot re-assign it later.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
scordle725 is offline Offline
4 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Talking with the hardware
Next Thread in Java Forum Timeline: code repeatedly 2 ask user 4 a password until correct (=Java) but cant c wots wrong.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC