Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2007, 09:52 AM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
FInal field cannot be assigned
I have following code which raises exception:
Code:
public class Test { static final int STACK_EMPTY = -1; static int STACK_FULL = 10; public static void main(String[] args) { STACK_FULL = 12; STACK_EMPTY = 2; } }
Exception:
Code:
The final field Test.STACK_EMPTY cannot be assigned
If you cant reassign value to a final attribute, then what is the use of it?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-13-2007, 10:57 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Its used for constants (note that constants, by style, should be all capital letters, separated by underscores). For something you never want to change by accident in your code:
Code:
public final MAX_NUMBER_USERS = 10;
final will just ensure that that number is never changed.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-13-2007, 01:41 PM
Member
 
Join Date: Dec 2007
Posts: 11
gulapala is on a distinguished road
Please know the difference when the final keyword is used

1. with variables.
2. with methods.
3. with classes.

It would help you.
__________________
Thanks & Regards, G.Rajasekhar
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-13-2007, 03:26 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Thanks all of you.
Its clear in my mind now. I feel I am improving now
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
get numeric value from a text field Lehane_9 New To Java 2 06-14-2008 04:19 AM
Reading a Field in a Binary File janakiram.attuluri Advanced Java 2 01-09-2008 11:47 AM
Help with define an integer field trill New To Java 1 08-07-2007 08:32 AM
problem with date field Ed Database 2 06-12-2007 05:27 PM
Final field question derrickD Advanced Java 1 04-28-2007 11:37 PM


All times are GMT +3. The time now is 08:14 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org