What is the difference between Static and final?

Showing Answers 1 - 13 of 13 Answers

vijay

  • Nov 8th, 2006
 

Static variable can change their values, final variables can not be changed they are constants . Static variable it attached to their class not with the object only one copy of static variable is exists and they can be called with reference of their class only final classed can not be extended and their are not static classes.

  Was this answer useful?  Yes

Ram

  • Jan 2nd, 2007
 

Static variables are initialized when the Class Loader loads the class and hence can be access in the static block declaration of the class without declaring an object. Whereas the final variable is only accessible after the declaration of an instance of an object. (Sorry to be very technical)

1.Static variables (also called class variables) only exist in the class they are defined in. They are not instantiated when an instance of the class is created. In other words, the values of these variables are not a part of the state of any object. When the class is loaded, static variables are initialized to their default values if no explicit initialization expression is specified 
Final variable:values of final variables cannot be changed.
2.Static methods are also known as class methods. A static method in a class can directly access other static members in the class. It cannot access instance (i.e., non-static) members of the class, as there is no notion of an object associated with a static method. However, note that a static method in a class can always use a reference of the class's type to access its members, regardless of whether these members are static or not.
Final methods:cannot be  overriden.

  Was this answer useful?  Yes

Amit Patil

  • Sep 19th, 2007
 

Static is used for variables and methods belonging to the class.
Final is used for constants.There can be final variables,methods and classes.

Final variables cant be modified.
Final methods cant be overridden.
Final classes cant be subclassed.

A variable may be final and static both.

  Was this answer useful?  Yes

vanigeetha

  • Feb 9th, 2008
 

Static variables are marked final.
Static method can't be instantiated.
Static method can't be overloaded & overridden.

Final variable can't be modified.
Final variables are implicitly final.
Final methods can't be overriddern.
Final class can't be subclassed.

  Was this answer useful?  Yes

sampra

  • Feb 11th, 2008
 

static varibale is a such type varible which loaded in to memory at class loading tim only one copy of varible is accessble in entire program

final variable is such type varible which value we cant change.JVM is not responsble to intilize the final varible,we ahve to iitilize,uninitilize fianl varible gives compilation time error

if ant dout thn plss lemme know

venkata

  • Mar 18th, 2013
 

Static: Attributes whose value remains same throughout all its instances , But can be changed by Any instance
Final: Attributes whose values remains same throughout every Specific instance of the class

Static Final: Attributes whose value remains same throughout all its instances , But cannot be changed by Any instance. (This is Truly the GLOBAL Variable)

  Was this answer useful?  Yes

dharani

  • Jun 3rd, 2014
 

Static variable is a global variable shared by all the instances of objects and it has only single copy.Final variable is a constant variable and it cant be changed.

  Was this answer useful?  Yes

Esmelealem

  • Jul 14th, 2015
 

Esmelealem

Most of you people answered the above question that static variables can be changed. Can we modify the following code of the variable value?

Code
  1.  

  2. static String s="java";

  Was this answer useful?  Yes

Jrradhika7

  • Jul 16th, 2015
 

String is immutable.

  Was this answer useful?  Yes

SHWETHA g

  • Aug 31st, 2015
 

"Static" keyword is used to a variable/method where a value of that variable has to be common to all objects created for example: bank interest rate for farmers loan common to all farmers.
where as "final" is to make a method or variable that should not be modified once after implementing.

  Was this answer useful?  Yes

Jitendra singh

  • Sep 23rd, 2015
 

Actually main reason that new make a class create only print my name not use object. You can create a simple program without using object this reason Java not 100% object oriented language

Code
  1. class jk

  2. {

  3. public static void main(String args[]JK)

  4. {

  5. System.out.printl("My name is jitendra singh")

  6. }

  7.   }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions