GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Mar-2008, 13:20
shyam_oec shyam_oec is offline
New Member
 
Join Date: Jan 2008
Posts: 16
shyam_oec has a little shameless behaviour in the past

What's nature of final constants


It's well known that ihis code will generate error
JAVA Code:

short a=5;
short b=6;
short c=a+b;
OR
short c=a+5;

because a+b OR a+5 is implecitely converted to int type,and this value is being assigned to short type.
Look at the code below
JAVA Code:

final short a=5;
short b=6;
short c=a+5;

this code works fine.can anyone explain what's going within jre when a+5 is encountered here.Is a+5 not imlecitely converted to int,if not why?and how the code worked?
  #2  
Old 25-Apr-2008, 13:23
JustinFox JustinFox is offline
Junior Member
 
Join Date: Mar 2008
Posts: 59
JustinFox will become famous soon enough

Re: What's nature of final constants


Quote:
Originally Posted by shyam_oec
It's well known that ihis code will generate error
JAVA Code:

short a=5;
short b=6;
short c=a+b;
OR
short c=a+5;

because a+b OR a+5 is implecitely converted to int type,and this value is being assigned to short type.
Look at the code below
JAVA Code:

final short a=5;
short b=6;
short c=a+5;

this code works fine.can anyone explain what's going within jre when a+5 is encountered here.Is a+5 not imlecitely converted to int,if not why?and how the code worked?

When you use the final keyword, it prevents the variable from being changed, in either type or value throughout the rest of the program.

Justin Fox
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Harry Potter and the Deathly Hallows - The Final Book Free Nyyphon Member Announcements, Advertisements & Offers 0 25-Aug-2007 06:42
Seems Final update seohp Open Discussion Forum 0 28-Apr-2007 13:55
D3D error when running fullscreen games/programs - help?! daa709 Computer Hardware Forum 4 01-Jul-2005 08:03
What's happening to nature? priyanka Open Discussion Forum 7 30-Oct-2004 12:58
Socrates the final moments.. paulselhi Open Discussion Forum 0 13-Feb-2004 08:24

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:20.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.