aspose file tools
The moose likes Beginning Java and the fly likes effect of private static final objects in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "effect of private static final objects in java?" Watch "effect of private static final objects in java?" New topic
Author

effect of private static final objects in java?

Vinney Shanmugam
Ranch Hand

Joined: Aug 27, 2008
Posts: 104
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

Joined: Jan 28, 2008
Posts: 5575

it is a constant which is encapsulated
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14492
    
  23

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
jQuery in Action, 2nd edition
 
subject: effect of private static final objects in java?