Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final keyword

 
alec stewart stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i have declared a variable as
final int a;
in a public class
can i access that variable in other class
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi alec, yes you can.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying it would have probably been less work than formulating the question... :roll:
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would control the visibility by using "private", "protected", "public" or default/package (no modifier, as in your example), just like any other instance variable. The "final" simply means it can't be changed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic