Static final variables

Static final variables

View Answers

February 26, 2009 at 6:47 AM

Hi,

static final variable u can access in non-static method.

but the variable should has accessibility, means check the access specifier.

the following example may be useful for u.

class Xyz{
private static final String name="xyz";

public void displayData(){

System.out.println("name is "+name);//within class u can access the variable 'name'
}
}

class Abc extends Xyz{
public void display(){

System.out.println("name is "+name);//here u can't access the variable 'name'.
}
}


regards,

siva kumar









Related Tutorials/Questions & Answers:
Static final variables - Java Beginners
Static final variables  can a static final variable be accessed by a instance (non-static)method?  Hi, static final variable u can... Xyz{ private static final String name="xyz"; public void displayData
private static final
private static final  Why there is necessary to make a variable private static final
Advertisements
Static & Instance variables in java
Static & Instance variables in java  What are the Difference between Static & Instance variables in java
ModuleNotFoundError: No module named 'static_variables'
ModuleNotFoundError: No module named 'static_variables'  Hi, My... named 'static_variables' How to remove the ModuleNotFoundError: No module named 'static_variables' error? Thanks   Hi, In your
Variables
Variables  What are the difference between Static variables, instance variables and local variables
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
Java final keyword
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...Java final keyword The final is a very important keyword in java, which
Static
Static  Can i know the real time example for Static method and final variables with defenition? Thank you
PHP Variables Static
PHP Variables Static PHP static variable is used to remember the value... is running a static variable is only retained by the function , but it is NOT shared... use PHP static statement that tells the function to remember the location
interface variables - Java Beginners
interface variables  why interface variables are final? explain me with good program example?? i knw why the variable is static but,i dont knw why it is final by default? thanks in advance
The final Keyword
final methods, final classes, final data members, final local variables and final parameters.  ADS_TO_REPLACE_1  variables: A variable declared... The final Keyword      
static
,then go for static methods. If we want variables those values will not be changed from object to anther object,then go for static variables...(According to my...Static Concept  in what are all the situation we may use static
static
is applied to member variables, it means that the static variable is shared among all...static  what r the main uses of static in java   Hi Friend, The Static means that a certain object/variable is resident in memory
static
in all objects.They are not re-created or re-initialized. Static variables...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
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
final keyword
final keyword  why is final keyword used in java
Final Methods - Java Tutorials
as static, final and public are known as named constants. Given below a example of named constant : public class Maths{ public static final double x...The final Keyword in Java In Java, final keyword is applied in various context
Final Keyword
Final Keyword  hello, What is final?   hiiADS_TO_REPLACE_1 In case of class if we use final then this class can not be extended or final class may not be subclassed. A final method can't be overridden when its class
final variable
final variable  Please give some easiest and understanding example program for final variable
interface variables - Java Interview Questions
interface variables  why interface variables are final? explain me with good program example?? i knw why the variable is static but,i dont knw why it is final by default? thanks in advance..  Hi Friend, The final
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
Java final
classes, final data members, final local variables and final parameters. 1. variables: A final variable can be set once and only once. 2. methods: A final method... Java final      
Java final Keyword Example
() { ...... } public static final void methodName2...() { ...... } public static final void methodName2... methodName2() { ...... } } Keyword final with Variables
final grade
final grade  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point...?s final grade from 50-100. Evaluate the Final grade and display the Point
Variables in Java
of variables: Instance Variables (Non-static fields): In object oriented... of the class has its own set of values for these non-static variables so we can say... if not initialized.   Class Variables (Static fields
static methods
static methods  why static methods cannot read or write the instance variables
getting variables
getting variables   how to get variables from servlet program to webservice program
PHP Static Variable and Methods
PHP Static Methods and Variables: In this tutorial we will study when we should use static methods and variables. Static keyword is used to make only one.... Example of PHP Static Variables & Methods : <?phpADS_TO_REPLACE_2 class
What are instance variables?
for these non-static variables so we can say that these are related to objects (instances of the class).Hence these variables are also known as instance variables...What are instance variables?   Hi, What are instance variables
Environment variables
Environment variables  How to set Environment Variables in JAVA 6 n Tomcat 6 CLASSPATH, JAVA_HOME, PATH, & CATALINA variables plzzz plzz help me
static keyword
static keyword  Hii, In which portion of memory static variables stored in java. Is it take memory at compile time? thanks deepak mishra
static keyword
Static Variables Static variables are class variables that are shared... and not to object(instance). 2)Static variables are initialized only once , at the start... variables). 2)A static method can call only other static methods and can not call
static functions
static functions  Give some brief defenition for 1. Static Variables 2. Static Functions 3. Instance Variable  Static Variables Static... variables. 3)A single copy to be shared by all instances of the class. 4)A static
Final method in java
FinalDemo { final static int a=10; public static void main(String args...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
Kotlin Variables
value can't be changed after first initialization. This is like static final...Kotlin Variables Example Learn to create and use variable to store values... variables in Kotlin.ADS_TO_REPLACE_1 Here are two ways of declare 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
Variables in Java
. class/static variables. Local variables. Instance variable : Instance... variables are used by all method of a class unless method is marked as static..., variable inside a class and static class. Static variables is also called
Static Variable
of a class, an object, is created. When static is applied to member variables...Static Variable  What is the basic use of introducing static variable type in java?Please explain clearly....   The Static means
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
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 Variables Help Please!
Java Variables Help Please!  Hi, I just started with java and i need... class ProjectCS { public static void main(String[] args) { welcome(); menu(); } public static void welcome() { System.out.println
Java - Declaring variables in for loops
Java - Declaring variables in for loops  Java - Declaring variables in for loops
instance variables - Java Beginners
instance variables  instance variables
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
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display... input a student?s final grade from 50-100. Evaluate the Final grade and display
Final Key Word in Java
.style1 { text-align: center; } Final key word in java In java final is a key word used in several different contexts. It is used before a variable, method, and classes so that they cannot be changed latter. Final Variables
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks

Ads