Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final variables

 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between the following codes:
1)code one:
public static void main(String []args)
{
final int i = 100;
byte b = i;
System.out.println(b);
}
==================================================
2)Code two:
public static void main(String []args)
{
int i = 100;
byte b = i;
System.out.println(b);
}
==================================================
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Java Language Specification for a formal definition:final (�4.5.4)
Basically, a variable declared final is a constant -- its value cannot be changed once assigned.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic