This week's book giveaway is in the Cloud forum.
We're giving away four copies of The Business Blockchain and have William Mougayar on-line!
See this thread for details.
Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

effect of private static final objects in java?

 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know what will be the effect of delcaring an object as

private static final object.


What is the use of declaring an object of class as private static final?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is a constant which is encapsulated
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15627
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating a private static final object as in line 3 of your code doesn't do anything special to class a. Class a still has a public, no-args constructor (the one that the compiler automatically generates when you don't specify a constructor yourself).

So inside a method in class b, you can still do this:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic