private static final

private static final

Why there is necessary to make a variable private static final?

View Answers

March 16, 2011 at 1:01 PM

Making a member private, means it's only visible to objects of the same class (unless, of course, expose via a public getter method.

Making it static means that there's only one instance of that particular member variable. This is good since there is no point having more than one instance of a constant.

Making it final, means that it can only be assigned once, alowing the compiler to optimize the bytecode since it is known that the value of that variable is never going to change once assigned.

Ads









Related Tutorials/Questions & Answers:
private static final
private static final  Why there is necessary to make a variable private static final
final
final  what does final means in "public static final void main (string args[])" ?   keyword final can be assigned only once. They cannot be modified
Advertisements
Static
Static  Can i know the real time example for Static method and final variables with defenition? Thank you
The final Keyword
. private and static methods are always implicitly final... The final Keyword       The final is a keyword. This is similar to const keyword in other
Final Methods - Java Tutorials
; The fields which are declared as static, final and public are known as named...{ public static final double x = 2.998E8; } final method arguments You can also...The final Keyword in Java In Java, final keyword is applied in various context
final keyword
final keyword  why is final keyword used in java
final variable
final variable  Please give some easiest and understanding example program for final variable
STATIC
STATIC  WHAT IS STATIC BLOCK?EXPLAIN , AND WHAT IS THE DIFFERENCE BETWEEN STATIC BLOCK AND STATIC METHOD?   A STATIC block is automatically... between static block and static method: static block will execute when ever
private and protected
private and protected  what is diffrence between private and protected
static
Static Concept  in what are all the situation we may use static...,then use static blocks and without creation of object we need to perform some task,then go for static methods. If we want variables those values will not be changed
static
static  what r the main uses of static in java   Hi Friend, The Static means that a certain object/variable is resident in memory and accessed each time an instance of a class, an object, is created. When static
private method
private method  how can define private method in a class and using...; return(size); } } public class useOfthisoperator { public static void main...){ this.length=l; this.breadth=b; } private int calculate
static
static  What is the exact need of declaring a variable as static?   A static variable is a variable who's single copy in memory is shared by all objects,so any modifications to the static variable will modify it's value
Java final keyword
Java final keyword The final is a very important keyword in java, which... with the name "Final" in a Java program. We can have final methods, final classes, final data members, final local variables and final parameters. When
static
redeclare static variable in the inherited class  can we redeclare static variable in the inherited class like this: public class StaticClass1 { class StaticClass1{ static int noOfInstances; StaticClass1
private constructor
private constructor  can we extend from a class which is having private constuctor
private method
private method  how can define private method in a class and using...; return(size); } } public class useOfthisoperator { public static void main...; } } public class useOfthisoperator { public static void main(String args
Final method in java
the program it act like a constant. public class FinalDemo { final static int a=10...Final method in java In this section we will learn about Final method in java.... If final is used with method that method will not be overridden in subclass, if final
Java final Keyword Example
final void methodName1() { ...... } public static final... methodName1() { ...... } public static final void methodName2... of the class in which they are declared. Likewise, the blank final static variable
What is final class?
What is final class?  Hi, What is final class? thanks   Hi, A final class is not be saubclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable
changing final Boolean value in SwingUtilities.invokeLater()
static boolean doCommit() { final boolean success = true...changing final Boolean value in SwingUtilities.invokeLater()  Hi, I have a problem with setting final Boolean value in second time
Java Final Variable
Java Final Variable  I have some confusion --Final variable has single copy for each object so can we access final variable through class name,or it is necessary to create object for accessing final variable
Private Cloud Hosting
Private Cloud Hosting  Hi, What is Private Cloud Hosting? What are the benefits of Private Cloud Hosting? Thanks
Static
an instance of a class. Static methods are implicitly final method, since overriding... final. However, a static method can't be overridden by a nonstatic method. Or we... Static       Static
Java final
Java final      ... entity which makes it unchangeable later. We can have final methods, final classes, final data members, final local variables and final parameters. 1
Can a abstract class be declared final?
Can a abstract class be declared final?   Hi, Can a abstract class be declared final? Thanks
Can a main method be declared final?
Can a main method be declared final?   Hi, Can a main method be declared final? Thanks   Hi, Yes we can. The final method can be declare as follows: public final String convertCurrency() The final method can't
ModuleNotFoundError: No module named 'Final_Project'
ModuleNotFoundError: No module named 'Final_Project'  Hi, My... 'Final_Project' How to remove the ModuleNotFoundError: No module named 'Final_Project' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Outliers-final'
ModuleNotFoundError: No module named 'Outliers-final'  Hi, My... named 'Outliers-final' How to remove the ModuleNotFoundError: No module named 'Outliers-final' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'spriteutil-final'
ModuleNotFoundError: No module named 'spriteutil-final'  Hi, My... named 'spriteutil-final' How to remove the ModuleNotFoundError: No module named 'spriteutil-final' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'final-class'
ModuleNotFoundError: No module named 'final-class'  Hi, My Python... 'final-class' How to remove the ModuleNotFoundError: No module named 'final-class' error? Thanks   Hi, In your python environment

Ads