answersLogoWhite

0

The static modifier, in combination with the finalmodifier, is used to define constants in Java. The finalmodifier indicates that the value of the field cannot change. In addition, the access modifier could be public, protected, or private depending on the scope of the constant that is needed.

Example:

public static final double PI = 3.141592653589793;

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

How the jvm is able to access your class even you declare it using default access specifier but the same class is not accessed from other class which is declared in another package?

The JVM knows about all of your classes, no matter what package they are in or what access specifier you declared them with. The access specifier is only used to limit access from other classes.


What array used for in c?

Arrays are used when you require constant-time random-access to a collection of anonymous variables of the same type.


What is the difference between an auto storage class and a register storage class in c?

The register storage class specifier is typically used for a heavily-used primitive data type, such as a loop control variable, and indicates to the compiler that this variable should be stored in a machine register to reduce access time. However, there are very few registers available and they are limited in size, so the compiler is free to ignore the specifier, in which case the variable is treated as if it were specified as an auto storage class. The auto storage class specifier allows you to explicitly declare a variable with automatic storage. Such variables are treated as being local to the block, and will fall from scope when the block ends. Since this is the default behaviour of all local variables, the auto specifier is redundant.


In ANSI C you can hide data by using private access specifier Justify?

One can always declare a datatype as static which will limit the scope to the file only. this way data hiding can be achived. For more clearance on the same please refer 'the C programming language'. Data hiding means only relevant data is visible to the user and all the background information is hidden from the user. In c++, the variables are named as data members and these can be hidden with the help of private access specifier. In procedural languages, variables(global variables) are free to flow from functions to functions and hence they were not secured. But in C++, only the class in which the data members are being declared can access them by using private specifier. As, the data members and also member functions of a class cannot be accessed outside the class if they have private access so, they get hidden from the user and hence the data hiding is achieved. Also in inheritance when we derive a class from the base class then the derived class cannot access the private members of the base class. In addition, if a class is derived from another class privately i.e. for example syntax : class B : private A , is used then all the public and protected members (not private) becomes private to class B and cannot be accessed outside the class B, even by using the object of class B. Hence, data hiding is achieved in C++ through private access specifier.


Can an experiment that has sveral variables be used to explain a theory?

Yes. A good example of which is the Ideal Gas Law. PV=nRT You have four variables and one constant.


What are register variables in c?

A register specifier for a variable is a compiler hint that the variable is used often and should be kept in a CPU register. The compiler will treat the variable as automatic, but it will give it preference for staying in a register between sequence points.


Which operator is used 2 access ahidden global variables?

To access a hidden global variable, use the scope resolution operator ::


Explain the different access storage specifiers available in c?

The storage class specifiers in C and C++ are:autoexternmutableregisterstatictypedefA storage class specifier is used to refine the declaration of a variable, a function, and parameters


Why is it X and Y are the two variables?

Lots of the other letters of the alphabet are used for either constant numbers or variables that are based on certain formula. C for instance is the speed of light in a vacuum (a constant) m is normally used for mass (a variable). x and y were most likely used as they were letters least likely to be used for representation of anything else and so the idea stuck to use them as calculable variables. Hope this helps.


Why you are mark a class protected for inheritance?

Public, Private and Protected "keywards/ access modifiers" are used similarly as they are with variables. Protected variables, methods or class CAN ONLY be used by an inherited class.


What are the variables and constant in a homemade lava lamp?

Variables in a homemade lava lamp can include the type of oil and water used, the amount of food coloring added, and the size and shape of the container used. A constant in a homemade lava lamp could be the type of Alka-Seltzer tablet used to create the reaction that forms the bubbles.


What does the word constant mean in science laws?

In science, a constant is a measurement, usually in an experiment, that never changes. It is used to compare and/or contrast the values of other variables in the same situation.