• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final Variables are Very PowerFull (Check inside))

 
Hussain
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ranches,
Hope everyBudy fine Doing well in java. I was Shoked to c tht final variables are very powerfull (as long as they r compiled time Constant).just Check this out.
Class A
{
public static void main(String [] args)
{
final int F=10;
byte b=F;//will compile as F is a compile time constant
}
}
Opposite
Class A
{
public static void main(String [] args)
{
final int F=a();
byte b=F;//not compile as F is a not a compile time Constant
}
static int a()
{
return 1;
}
}
I can Say one Thing for Sure :-
JAVA is a Deep as OCEAN.

 
Suresh Bansal
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good One.
Sure, when you thing that you know all, at that point also you may find some thing that are interesting.
But i think that one should be able to analyse new concepts in the light of old ones as you might already must have.
In first case the variable is initialized with a literal but in second case it is not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic